'Outputting records from form to Report

I am using a button to open a report based on a few filter selections and it is mostly working how I want it to although there are a few issues.

Private Sub cmdCreateReport_Click()

    On Error GoTo Err_cmdCreateReport_Click

    Dim stDocName As String

        If IsNull(cboLookUp) Then
            MsgBox "Please select a Supplier Region.", vbInformation, "Region required"

            Me.cboLookUp.SetFocus

        Else
            stDocName = "rptRegion"

            DoCmd.OpenReport stDocName, [acViewReport], Regions, _
            "[Region] = '" & Me.cboLookUp & "'" & _
            "and [txtAgreementID] = " & Me.cboAgreement & "" & _
            "and [IsActive] = " & Me.chkActive
            
        End If

Exit_cmdCreateReport_Click

    Exit Sub

Err_cmdCreateReport_Click

    MsgBox Err.Description

    Resume Exit_cmdCreateReport_Click

End Sub
  1. The form itself doesn't display data but when I send to the report it displays. The form is blank but all the data is filtered almost correctly when exported as a report.
  2. The second combo box is still asking for a parameter even though I have done it nearly the same as the first. The only difference is the second gets a number instead of text. When asking for the parameter it has to be entered as the selection but will display all active under that region.
  3. The code to display the records in the form based on active or inactive is supposed to work by displaying only active or all. I want to make this the case in the report as well as at the moment it will display either active or inactive based on the checkbox ticked. Is there a way to add an If statement into the where condition or to call this line in order to get active if ticked or all if not ticked? Like IIf([Forms]![rfrmRegionSearch]![chkActive],-1,"*") The criteria in the Query to display active or all.
Private Sub cboLookUp_AfterUpdate()

    cboLookUp.Requery
    cboAgreement.Requery
    Me.Filter = "Region = '" & cboLookUp & "'"
    
End Sub

Private Sub cboAgreement_AfterUpdate()

    cboAgreement.Requery
    Me.Filter = "txtAgreementID = " & cboAgreement & ""

End Sub

Private Sub chkActive_AfterUpdate()

    chkActive.Requery
    cboLookUp.Requery
    Me.Filter = "IsActive = " & chkActive & ""

End Sub

The filter code for the two Combo Boxes and checkbox cboAgreement is the combo retrieving a number

If there is any other information required please let me know.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source