This is stumping me, although it must be something obvious.
I have an unbound form with a text box for users to enter a date. I want to take that date and generate an SQL statement that will open up my main form showing entries with the specified date. Here is what I have, but it will not work. (similar statements work for other, non date-related textboxes on my form, so I am pretty sure this is a date-specific syntax problem)
'This creates a dynamic SQL statement that searches the ADR log
Dim mySql As String
Dim myWhere As String
'search the [tblADR] table
mySql = "SELECT * FROM tblADR"
myWhere = ""
If Nz(Forms!frmsearchadr!txtadrdate) <> "" Then
If myWhere <> "" Then
myWhere = myWhere & " AND"
End If
myWhere = myWhere & " ([letterdate] like " & Forms!frmsearchadr!txtadrdate & ")"
End If
If myWhere <> "" Then
mySql = mySql & " WHERE " & myWhere
End If
DoCmd.OpenForm "frmADR", , mySql
DoCmd.Close acForm, "frmsearchadr"
End Sub
TIA for any suggestions...
I have an unbound form with a text box for users to enter a date. I want to take that date and generate an SQL statement that will open up my main form showing entries with the specified date. Here is what I have, but it will not work. (similar statements work for other, non date-related textboxes on my form, so I am pretty sure this is a date-specific syntax problem)
'This creates a dynamic SQL statement that searches the ADR log
Dim mySql As String
Dim myWhere As String
'search the [tblADR] table
mySql = "SELECT * FROM tblADR"
myWhere = ""
If Nz(Forms!frmsearchadr!txtadrdate) <> "" Then
If myWhere <> "" Then
myWhere = myWhere & " AND"
End If
myWhere = myWhere & " ([letterdate] like " & Forms!frmsearchadr!txtadrdate & ")"
End If
If myWhere <> "" Then
mySql = mySql & " WHERE " & myWhere
End If
DoCmd.OpenForm "frmADR", , mySql
DoCmd.Close acForm, "frmsearchadr"
End Sub
TIA for any suggestions...