My tendency is to create dynamic SQL. Here's an example:
Code:
Public Function SearchBookings()
Dim strSQL As String
On Error GoTo ErrorHandler
If IsNumeric(Me.txtResNum) Then
strSQL = strSQL & " AND ResNum = " & Me.txtResNum
End If
If IsDate(Me.txtFromDate) And IsDate(Me.txtToDate) Then
strSQL = strSQL & " AND ResDate Between " & Format(Me.txtFromDate, conJetDate) & " And " & Format(Me.txtToDate, conJetDate)
ElseIf IsDate(Me.txtFromDate) Then
strSQL = strSQL & " AND ResDate = " & Format(Me.txtFromDate, conJetDate)
End If
If Not IsNull(Me.cboCompany) Then
strSQL = strSQL & " AND conCompany = '" & Me.cboCompany & "'"
End If
strSQL = "SELECT ResNum, FullName, PickupAddy, ResDateTime, Direction " _
& "FROM qryAllRes " _
& "WHERE 1=1" & strSQL _
& " ORDER BY ResDateTime"
Me.lstReservations.RowSource = strSQL
ExitHandler:
Exit Function
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description & " in SearchBookings "
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Function
Private Sub cboCompany_AfterUpdate()
SearchBookings
End Sub