Im having problem running the program. Its say i have incorrect syntax at my strsql coding
Code:
Private Sub ComboBox1_Change() Dim rst As ADODB.Recordset 'Initialize Recordset Set rst = New ADODB.Recordset On Error GoTo errhandle strSq1 = "SELECT DISTINCT activitydesc,materialid FROM activity_table " & _ "WHERE activityid in " & _ "(Select distinct activityid from sample where(sampledt BETWEEN StartDt AND EndDT)" ' Get Start Date & End Date StartDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 00:00:00") EndDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 23:59:59") ' Re-Connect to Database MakeConnection If Module1.connectSQLSrv(strRegLogin, strRegPwd, strRegDB, strRegServer) Then ' Cursor and Lock Characteristic ' adOpenDynamic = high Concurrency & Scrollable ' adLockOptimistic = other users able to access data ' adCmdText = Command Type (Text) 'Open Recordset rst.Open strSql, sqlConnection, adOpenDynamic, adLockOptimistic, adCmdText With rst If .RecordCount = 0 Then ComboBox1.Clear ComboBox1.AddItem rst![Request] Do While Not .EOF If Not IsNull(.Fields(0).Value) Then ComboBox1.AddItem (.Fields(0).Value) End If .MoveNext Loop Else Exit Sub End If End With Set rst = Nothing Else 'Frm Login activate = asking for user login 'MsgBox "Login Failed, please retry!", vbExclamation bolConnected = False Module1.MakeConnection End If Exit Sub errhandle: MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error!" bolConnected = False<<< Having error on this line If Not sqlConnection Is Nothing Then Set sqlConnection = Nothing End If End Sub
Comment