How to filter Report Using List Box

sunny88

New member
Local time
Today, 15:19
Joined
Jun 29, 2014
Messages
8
Hey Guys.
I am a beginner with access and i am not good with VBA.My problem is the following.

I have a query based report Linked to a form. That is, in my form, i have a combo box. Selecting this combo box pulls out a certain field values in list box in the same form. (Cascading Combo/ List Boxes).

So after i select a certain value in combo box, it shows a certain field values in the list box. Now, i want to open a report and view only the records that has the selected combo box and list box values.

Note: I have seen a guy made an access report based on a query. He made a form with a combo box and a list box. The report is based on the combo box value selected by the user. Once, the user selected a value in the combo box, the list box updates automatically. ( I have done till here successfully). Then he used a toggle button on the same form. This toggle button opens the report with the combo box value as the criteria but filters the report based on the field value in the list box.

Can any help me how to place a toggle button with a filter command to open a query based report?
 
Hi,
the following code added to a command button to open your report will filter dependant on a miriad of factors - textboxes or combos or even check boxes

Code:
Private Sub cmdFilterRecords_Click()
    Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#mm\/dd\/yy\#"

    If Not IsNull(Me.txtTSM) Then
        strWhere = strWhere & "([TSM] = """ & Me.txtTSM & """) AND "
    End If
    
   

    If Not IsNull(Me.txtRecordedBy) Then
        strWhere = strWhere & "([Recorded_By] Like ""*" & Me.txtRecordedBy & "*"") AND "
    End If
     
    

    If Not IsNull(Me.txtEndDate) Then
        strWhere = strWhere & "([Recording_Date] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
    End If

    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
        MsgBox "No criteria", vbInformation, "Nothing to do."
    Else
        strWhere = Left$(strWhere, lngLen)

        
        Me.Filter = strWhere
        Me.FilterOn = True
    End If

This will filter the form then use docmd.openreport to open your report
 

Users who are viewing this thread

Back
Top Bottom