Hi All,
I have a dialog form in Access where a user selects certain criteria in different combinations or by just one criteria within several simple listboxes and then clicks on the filter report button. I have some selections that when selected and filtered by give me a report filtered by the selection. I have other selections within the listbox that do not work and I don't know why. I have tested the code by pasting MSGBOX so I can see the build string.
I am new to coding. Below is the code for one of my listboxes. I want to filter by sample_id '0001'. When I placed the message box I see where it is searching for '0001', but the report is not filtered I see a blank report. The data is there. I can see that sample if I print preview the report and when I run the query that builds the report.
' Build criteria string from lstSample listbox
For Each varItem In Me.lstSample.ItemsSelected
strSample = strSample & ",'" & Me.lstSample.ItemData(varItem) _
& "'"
Next varItem
If Len(strSample) = 0 Then
strSample = "Like '*'"
Else
strSample = Right(strSample, Len(strSample) - 1)
strSample = "IN(" & strSample & ")"
End If
When I enter the following in the immediate window the report is filtered!! Why does my code above not do that? And this code does!?
DoCmd.OpenReport "rpt_contaminant", acViewPreview, , "Sample_ID = '0001'"
I found an article on the web where it sounds like there is a bug with Access. It sounds like the FILTERON is not set reliably for reports. This is what the article said: If you open a form with a WhereCondition, Access reports the form's FilterOn is True. If you open a report with a WhereCondition, Access may not set its FilterOn property. Any code in the report's events is therefore unable to determine whether if the Filter is applied or not." Allen Browne is the author. (
He doesn't suggest what to do to fix it or a work around. I am certain this is what is happening to my report filter. I tested it using ?Report!rpt_contaminant.FilterOn and I get a False.
Anyone have any ideas?
Thank you SO much in advance,
Maribel
I have a dialog form in Access where a user selects certain criteria in different combinations or by just one criteria within several simple listboxes and then clicks on the filter report button. I have some selections that when selected and filtered by give me a report filtered by the selection. I have other selections within the listbox that do not work and I don't know why. I have tested the code by pasting MSGBOX so I can see the build string.
I am new to coding. Below is the code for one of my listboxes. I want to filter by sample_id '0001'. When I placed the message box I see where it is searching for '0001', but the report is not filtered I see a blank report. The data is there. I can see that sample if I print preview the report and when I run the query that builds the report.
' Build criteria string from lstSample listbox
For Each varItem In Me.lstSample.ItemsSelected
strSample = strSample & ",'" & Me.lstSample.ItemData(varItem) _
& "'"
Next varItem
If Len(strSample) = 0 Then
strSample = "Like '*'"
Else
strSample = Right(strSample, Len(strSample) - 1)
strSample = "IN(" & strSample & ")"
End If
When I enter the following in the immediate window the report is filtered!! Why does my code above not do that? And this code does!?
DoCmd.OpenReport "rpt_contaminant", acViewPreview, , "Sample_ID = '0001'"
I found an article on the web where it sounds like there is a bug with Access. It sounds like the FILTERON is not set reliably for reports. This is what the article said: If you open a form with a WhereCondition, Access reports the form's FilterOn is True. If you open a report with a WhereCondition, Access may not set its FilterOn property. Any code in the report's events is therefore unable to determine whether if the Filter is applied or not." Allen Browne is the author. (
He doesn't suggest what to do to fix it or a work around. I am certain this is what is happening to my report filter. I tested it using ?Report!rpt_contaminant.FilterOn and I get a False.
Anyone have any ideas?
Thank you SO much in advance,
Maribel