I have a search form that enables the user to search the data in a table, and this works fine. But I would like to have the option to search between two dates as well, and this is where the problem lies (mismatch error):
The red text is where the problem lies.
I have also tried:
But this is also coming out as an error??
Thanks alot guys for taking the time
Mads
Code:
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the RowSource
strSQL = "SELECT tblKalkyle.KalkyleID, tblKalkyle.Selger, tblKalkyle.Kundenavn, tblKalkyle.Truck, tblKalkyle.Konsernnavn, tblKalkyle.Dato " & _
"FROM tblKalkyle"
strWhere = "WHERE"
strOrder = "ORDER BY tblKalkyle.KalkyleID;"
'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtID) Then '<--If the textbox txtFName contains no data THEN do nothing
strWhere = strWhere & " (tblKalkyle.KalkyleID) Like '*" & Me.txtID & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.txtSøk) Then
strWhere = strWhere & " (tblKalkyle.Søkekriterier) Like '*" & Me.txtSøk & "*' AND"
End If
If Not IsNull(Me.txtKunde) Then
strWhere = strWhere & " (tblKalkyle.Kundenavn) Like '*" & Me.txtKunde & "*' AND"
End If
If Not IsNull(Me.txtTruck) Then
strWhere = strWhere & " (tblKalkyle.Truck) Like '*" & Me.txtTruck & "*' AND"
End If
[COLOR=Red]If Not IsNull(Me.txtDato) Then
strWhere = strWhere & " (tblKalkyle.Dato) Between '*" & Me.txtDato And Me.txtDato2 & "*' And"
End If[/COLOR]
If Not IsNull(Me.txtKonsern) Then
strWhere = strWhere & " (tblKalkyle.Konsernnavn) Like '*" & Me.txtKonsern & "*' AND"
End If
If Not IsNull(Me.txtKNummer) Then
strWhere = strWhere & " (tblKalkyle.Kundenummer) Like '*" & Me.txtKNummer & "*' AND"
End If
If Not IsNull(Me.txtSelger) Then
strWhere = strWhere & " (tblKalkyle.Selger) Like '*" & Me.txtSelger & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = MID(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub
The red text is where the problem lies.
I have also tried:
Code:
[COLOR=Red]If Not IsNull(Me.txtDato) Then
strWhere = strWhere & " (tblKalkyle.Dato) Between Like '*" & Me.txtDato And Me.txtDato2 & "*' And"
End If[/COLOR]
Thanks alot guys for taking the time
Mads
Last edited: