Hi all, I need some help, please
I have filter form with 2 text boxes – Date from (txt.Datefrom) and Date to txt.Dateto)…, and cbo_inspector.
My VBA code is working for Date but I wanna to set criteria and for cbo_inspector.
The code is:
Thise code is working perfect for the date from – to, but I wanna to set criteria for cbo_Inspektor, where there is field “Inspektor” in my query.
What it should be the code??? I want also to have message if the cbo_...... is empty…..” please enter a value”
I have filter form with 2 text boxes – Date from (txt.Datefrom) and Date to txt.Dateto)…, and cbo_inspector.
My VBA code is working for Date but I wanna to set criteria and for cbo_inspector.
The code is:
Code:
Private Sub cmd_Filter_Click()
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "rpt_ reference"
strDateField = "[Date]"
lngView = acViewPreview
If IsDate(Me.txt.Datefrom) Then
strWhere = "(" & strDateField & " >= " & Format(Me.txt.Datefrom, strcJetDate) & ")"
End If
If IsDate(Me.Dateto) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.Dateto + 1, strcJetDate) & ")"
End If
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
DoCmd.OpenReport strReport, lngView, , 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
Thise code is working perfect for the date from – to, but I wanna to set criteria for cbo_Inspektor, where there is field “Inspektor” in my query.
What it should be the code??? I want also to have message if the cbo_...... is empty…..” please enter a value”
Last edited by a moderator: