How do I reference the date range found in the relevant column header and the season code (from the start of the row) for the cell that is currently being processed in the loop as I need to pass these variables to the query.
How do I then insert the value returned by the query into the cell.
Below is the code I have so far which may be completely wrong.
Sub MultiSQL()
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rstSQL As ADODB.Recordset
Dim sqlQRY As String
Dim sqlCN As String
Dim sCusName As String
Dim sDateRange As String
Dim sSCode As String
Dim i As Long
Dim colCount As Long
colCount = Range("C3", Range("C3").End(xlToRight)).Count
For i = 1 To colCount
Set cnn = New ADODB.Connection
sqlCN = "Provider=SQLOLEDB; Server=BBB-SQL; Database=BBB-LIVE; Trusted_Connection=yes;"
cnn.Open sqlCN
sqlQRY = "SELECT SUM of [salesamount] As 'Summed Amount' " _
& "FROM [Value Entry] " _
& "WHERE [Customer] = '" & sCusName & "' AND [Date] BETWEEN '" & sDateRng & "' " _
& "AND [Season Code] = '" & sSCode & "' ;"
Set rstSQL = New ADODB.Recordset
rstSQL.Open sqlCN, cnn, adOpenDynamic
Next i
Bookmarks