CraigDouglas
Registered User.
- Local time
- Today, 15:23
- Joined
- Sep 14, 2016
- Messages
- 31
Hi, please help if you can. I have a form frmSwitchBoard on it I have two combo boxes cboMonthYearStart and the other cboMonthYearEnd. I have a button that opens up a report rptOrderFromStartMonthYearToEndMonthYear and I want it to filter the start month and year chosen in the first combo box to the end month and year chosen in the second box. The field I use to get my combo box info is called MonthAndYear. I would like the vba code to show all entries which are group as month and year if nothing is chosen in the combo box and I would like the report to filter the records from the chosen month year to the end month year that gets chosen. The code I have so far is:
End Sub
Code:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ErrorHandler
'Add filter
Dim frm As Form
Set frm = Forms!frmSwitchBoard 'Must Be Open
Dim strFilter As String
strFilter = ""
'If both are empty show everything
If Len("" & frm!cboMonthYearStart) = 0 And Len("" & frm!cboMonthYearEnd) = 0 Then
Me.Filter = ""
Me.FilterOn = False
Exit Sub
End If
From frm!cboMonthYearStart To frm!cboMonthYearEnd
End If
'Add filter
Me.Filter = strFilter
Me.FilterOn = True
CleanUpAndExit:
Exit Sub
ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume CleanUpAndExit
End Sub