Argh! DENNIS!!!! Build your string, ADD THE DEBUG.PRING strSQL... WHAT DOES IT SAY???? Do you see where there MIGHT BE two words without a SPACE between them!!!????
strSq1 = "SELECT DISTINCT activitydesc,ma terialid FROM activity_table " & "WHERE activityid in (Select distinct activityid from sample where(sampledt BETWEEN " & StartDt & " AND " & EndDT &")"
' Re-Connect to Database
The issue is specifically with the variables.
1. You need to give them the right values first, -before- you build the SQL string.
2. You SQL string did not break out the variables from the string properly.
When you pass a SQL string to be executed, it passes the entire string as it computes. If you don't break out your variables properly, in this case, your date range variables, it will choke on them.
In this case, your date range was just the WORDS, StartDt and EndDt, when really you wanted the VALUE of StartDt and EndDt respectively.
i manage to solve the initial problem with ur coding but my coding is have error 31 on this code :
errhandle:
MsgBox Err.Number & " : " & Err.Description , vbCritical, "Error!"
bolConnected = False
If Not sqlConnection Is Nothing Then
Set sqlConnection = Nothing
End If
End Sub
Some changes to my project now, instead of using the combobox to display the value, i need to display the value in excel cells. Wonder if anyone can help me with the code on my first post. Thanks in advance
Comment