Solved Mask with sub-mask filtered by 2 combined drop-down boxes and a checkbox, opening two different reports depending on the checkbox (1 Viewer)

Faoineag

Registered User.
Local time
Today, 10:05
Joined
Jan 7, 2018
Messages
99
Good evening everyone, as you see corresponding thread in Forms and Vba, your help has enabled me to filter a subform with 2 combined drop-down boxes and a checkbox and subsequently open a report. Now I would like to add a feature: if the checkbox is selected, clicking the button opens Report 1 (rptProductsFiltered), if it is not selected, clicking the button opens Report 2 (rptProductsFiltered_02). I modified the previous code (because in the db version of the other thread I was only opening one report) and inserted this:


Private Sub cmdApriReport_Click()
Dim strfiltro As String
strfiltro = "1=1"

If Not IsNull(Me.cboSceltaSottoCategorie) Then
strfiltro = strfiltro & " AND IDSottoCategorie = " & Me.cboSceltaSottoCategorie
End If

If Not IsNull(Me.cboSceltaTipo) Then
strfiltro = strfiltro & " AND IDTipoProdotto = " & Me.cboSceltaTipo
End If

If Me.chkCatEmmeti.Value = True Then
DoCmd.OpenReport "rptProdottiFiltrati_Attrezzature_Atletica_Emmeti", acViewPreview, , strfiltro
Else
DoCmd.OpenReport "rptProdottiFiltrati_Attrezzature_Atletica", acViewPreview, , strfiltro
End If

End Sub

At first it seemed to work, because but then I noticed that depending on whether the checkbox is selected or deselected one report opens or the other, however in both cases the items are not filtered (=they are all there, both those that have the checkbox selected and those that have it deselected). If you can suggest how to correct this, I would be grateful.
 

Attachments

The first rule of debugging is to set a breakpoint and test that the variables contain what you think they contain. I would set that breakpoint on the IF-test of the checkbox and then run the code. When it breaks, open the Immediate Window, and from there, use Debug.Print to verify the contents of strfiltro and Me.chkCatEmmeti.Value to verify that they are as you expected.

As a side note, you don't need .Value on a form's control because if the control actually HAS a value, its default property IS .Value - which mans that Me.chkCatEmmeti and Me.chkCatEmmeti.Value are the same, particularly since that is a checkbox.
 
Thank you. Now the code works, in the sense that the report is filtered by both the two combination boxes and the checkbox, but the same report always opens as a file, even though the data of the two are different in the sense that they correspond to the two reports. Where am I going wrong?
 

Attachments

I thank you, but the problem remains: the items are filtered correctly, in the sense that if I select the checkbox in the mask, the items with the selected checkbox appear in the report that opens, and vice versa, but the same report always opens. To explain further, the correct result should be: when I select the checkbox in the form, the yellow ‘rptProductsFiltered_02’ report should open, when the form checkbox is deselected, the green ‘rptProductsFiltered’ report should open. Instead, I always get the green report, but the data all have the checkbox flagged if I have flagged this in the form, while they all have the checkbox unchecked if the form checkbox is unchecked
 
the checkbox has Triple State, meaning if you see a dash (-), it means Null and there is no filter.
When either blank (unchecked) or checked, then there is filter.
 
Thank you, I have modified the code, added a report and it now works. I enclose the db with the code in case anyone needs it. Thanks again
 

Attachments

Users who are viewing this thread

Back
Top Bottom