CraigDouglas
Registered User.
- Local time
- Today, 06:34
- Joined
- Sep 14, 2016
- Messages
- 31
Please help. I have code that filters my report using the open event of the report but I want to have the code in the button on a form so I don't have to make many reports.
The combo boxes are called cboSubcategory and cboCustomer1 the button is called cmdOpenRptCustomerStockMain.
I have code in the open event which is similar just a few differences as I am doing a different report to test the code. I want to be able to see the results of the choice in the cboSubcategory, the cboCustomer1 and if selections of both are chosen together. Thank you for any help. Craig
Here is the code that is in the open event of the report
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ErrorHandler
'Add filter
Dim frm As Form
Set frm = Forms!frmSwitchboard2 'Must Be Open
Dim strFilter As String
strFilter = ""
'If both are empty show everything
If Len("" & frm!cboCustomer) = 0 And Len("" & frm!cboProductSubcategory) = 0 Then
Me.filter = ""
Me.FilterOn = False
Exit Sub
End If
'Customer
If Len("" & frm!cboCustomer) > 0 Then
strFilter = "[CustomerName] = Forms!frmSwitchboard2!cboCustomer"
End If
'ProductSubcategory
If Len("" & frm!cboProductSubcategory) > 0 Then
If Len(strFilter) > 0 Then
strFilter = strFilter & " And "
End If
strFilter = strFilter & "[ProductSubcategory] = Forms!frmSwitchboard2!cboProductSubcategory"
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
The combo boxes are called cboSubcategory and cboCustomer1 the button is called cmdOpenRptCustomerStockMain.
I have code in the open event which is similar just a few differences as I am doing a different report to test the code. I want to be able to see the results of the choice in the cboSubcategory, the cboCustomer1 and if selections of both are chosen together. Thank you for any help. Craig
Here is the code that is in the open event of the report
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ErrorHandler
'Add filter
Dim frm As Form
Set frm = Forms!frmSwitchboard2 'Must Be Open
Dim strFilter As String
strFilter = ""
'If both are empty show everything
If Len("" & frm!cboCustomer) = 0 And Len("" & frm!cboProductSubcategory) = 0 Then
Me.filter = ""
Me.FilterOn = False
Exit Sub
End If
'Customer
If Len("" & frm!cboCustomer) > 0 Then
strFilter = "[CustomerName] = Forms!frmSwitchboard2!cboCustomer"
End If
'ProductSubcategory
If Len("" & frm!cboProductSubcategory) > 0 Then
If Len(strFilter) > 0 Then
strFilter = strFilter & " And "
End If
strFilter = strFilter & "[ProductSubcategory] = Forms!frmSwitchboard2!cboProductSubcategory"
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