Hello,
1. I get type mismatch error at:
if either the start or end dates are left blank. I'm not sure why this is happening. both field types are "Short Date".
2. Also, after I clear "Refresh Button" the search fields on the form, Access is still detecting data and give an error message.
This seems like a simple search form but I'm having lots of problems with in for some reason.
The database is attached.
Thanks,
1. I get type mismatch error at:
Code:
strWhere = strWhere & "([run_date] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
if either the start or end dates are left blank. I'm not sure why this is happening. both field types are "Short Date".
2. Also, after I clear "Refresh Button" the search fields on the form, Access is still detecting data and give an error message.
This seems like a simple search form but I'm having lots of problems with in for some reason.
The database is attached.
Thanks,
Code:
Dim strWhere As String
strWhere = ""
Const conJetDate = "\#mm\/dd\/yyyy\#"
Dim lngLen As Long
If Not IsNull(Me.cmb_project_name.Value) Or Me.cmb_project_name.Value <> "" Then
strWhere = strWhere & "[run_name] = """ & Me.cmb_project_name & """ AND "
End If
'Date field example. Use the format string to add the # delimiters and get the right international format.
If Not IsNull(Me.txtStartDate.Value) Or Me.txtStartDate.Value <> "" Then
strWhere = strWhere & "([run_date] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
'strWhere = strWhere & "([run_date] >= " & (Me.txtStartDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since this field has times as well as dates.
If Not IsNull(Me.txtEndDate.Value) Or Me.txtEndDate.Value <> "" Then 'Less than the next day.
strWhere = strWhere & "([run_date] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
'strWhere = strWhere & "([run_date] < " & (Me.txtEndDate + 1) & ") AND "
End If
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Please indicate criteria."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
End If