I am trying to select a record from a Table base on a certain date that I select on an ActiveX calendar control on my Form. MY Db is Access XP and here is the code.
Private Sub CommandClick_Click()
Dim DateJ As Date
Dim strSQL As String
Dim RS As ADODB.Recordset
Dim Cn As ADODB.Connection
Dim nom As String
Dim Sconnect As String
'Database Path
Sconnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Markus\My Documents\Projet Sesco\Equipe de Vente.mdb"
Set Cn = New ADODB.Connection
Set RS = New ADODB.Recordset
Cn.Open Sconnect
Calendar5.SetFocus
DateJ = Calendar5.Value
strSQL = "SELECT * FROM CollègeQ WHERE " & DateJ & " = Date "
' strSQL = "SELECT * FROM CollègeQ"
Set RS = Cn.Execute(strSQL)
If Not (RS.BOF And RS.EOF) Then
TextTest.SetFocus
TextTest.Text = RS.Fields("Date").Value
Else
MsgBox "No Record Found"
End If
Cn.Close
Set RS = Nothing
Set Cn = Nothing
End Sub
When I comment out the First strSQL I always obtain the first column in the table. Using the first strSQL I get no record found. However, I know the records exists for the dates I select in the calendar. I have a test date in the table which is 1/1/2003 and I select this date on the calendar and still get no result when I click on the command button.
Any advice would be really appreciated.
Mark