Private Sub OK_Click()
On Error GoTo Err_Handler
Dim strReport As String
Dim strDateField As String
Dim StrWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "OT details"
strDateField = "[Month of Entry]"
lngView = acViewReport
If IsDate(Me.txtStartDate) Then
StrWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
End If
If IsDate(Me.txtEndDate) Then
If StrWhere <> vbNullString Then
StrWhere = StrWhere & " AND "
End If
StrWhere = StrWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
If Trim(Me.cbolocationbrief & "") <> "" Then
StrWhere = StrWhere & " And " & _
Application.BuildCriteria("[Area]", VarType(Me.cbolocationbrief.Column(0)), Me.cbolocationbrief.Column(0))
End If
Debug.Print StrWhere
[COLOR="Navy"] 'DoCmd.OpenReport strReport, lngView, , StrWhere
If Trim(Me.cbolocationbrief & "") <> "" Then
StrWhere = StrWhere & " And " & _
Application.BuildCriteria("[Area]", VarType(Me.cbolocationbrief.Column(0)), Me.cbolocationbrief.Column(0))
End If
[/COLOR] 'DoCmd.OpenReport "OT Details", acViewPreview, , "[Area]='" & Me.cbolocationbrief & "'"
DoCmd.OpenReport "OT Details", acViewPreview, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler
End Sub