I have the following code that I use often on forms which are used to provide report criteria:
For this one issue, I am dealing with an Events report. The form is intended to allow a user to choose 1 event from a drop down and view attendees based on RSVP. The user should be able to choose from a multiselect listbox of RSVP options. They can choose to just see Yes and Maybe, No and No Response, just Yes, etc. Whatever helps them get the event together.
This type of setup works great when all the criteria fields are in the main report control source...
(here is the code)
The commented out section is the problem I am having right now. That buildin works by the following function:
My issue here is that the stDocName = "rptEvent" has a query control source. It also has a subreport (rptEventSubRSVP) which has its own query control source.
The commented section:
is calling a multiselect listbox on the form to allow the user to select no options (i.e. bring back all RSVP choices for an event) or the buildIn (Yes OR No OR Maybe) of the RSVP options the user wants to view for an event.
The issue is that the MYRSVP field called here is on the subreport and in the control source for the subreport query. The above intial code needs to use this build in for the subreport query criteria, but I am not sure how to do that.
Can anyone help me make sense of this minor craziness?
Thanks!
misscrf
It is never too late to become what you could have been ~ George Eliot
For this one issue, I am dealing with an Events report. The form is intended to allow a user to choose 1 event from a drop down and view attendees based on RSVP. The user should be able to choose from a multiselect listbox of RSVP options. They can choose to just see Yes and Maybe, No and No Response, just Yes, etc. Whatever helps them get the event together.
This type of setup works great when all the criteria fields are in the main report control source...
(here is the code)
Code:
Private Sub cmdRunRSVPRpt_Click()
On Error GoTo Err_cmdRunRSVPRpt_Click
Dim strCriteria As String
Dim lbo As ListBox
Dim itm
Dim i As Long
Dim stDocName As String
strCriteria = "1=1 "
strCriteria = strCriteria & _
" AND ([PKEventID]) = " & Me.cboChooseEvent
' If Me.lstRSVP.ItemsSelected.Count = 0 Then
' strCriteria = strCriteria _
' & " AND 1=1"
' Else
' strCriteria = "1=1 "
' strCriteria = strCriteria & _
' BuildIn(Me.lstRSVP, "[rptEventSubRSVP].Report![MyRSVP]", "'")
' End If
'
stDocName = "rptEvent" ' check setting the recordsource for the report
DoCmd.OpenReport stDocName, acPreview, , strCriteria
Exit_cmdRunRSVPRpt_Click:
Exit Sub
Err_cmdRunRSVPRpt_Click:
Resume Exit_cmdRunRSVPRpt_Click
End Sub
The commented out section is the problem I am having right now. That buildin works by the following function:
Code:
Function BuildIn(lboListBox As ListBox, _
strFieldName As String, strDelim As String) As String
'send in a list box control object
'strFieldName is the name of the field in the report's record source
'strDelim is the delimiter for numbers use "" for text """" and dates "#"
Dim strIn As String
Dim varItem As Variant
If lboListBox.ItemsSelected.Count > 0 Then
strIn = " AND " & strFieldName & " In ("
For Each varItem In lboListBox.ItemsSelected
strIn = strIn & strDelim & lboListBox.ItemData(varItem) & strDelim & ", "
Next
'remove the last ", " and add the ")"
strIn = Left(strIn, Len(strIn) - 2) & ") "
End If
BuildIn = strIn
End Function
The commented section:
Code:
If Me.lstRSVP.ItemsSelected.Count = 0 Then
' strCriteria = strCriteria _
' & " AND 1=1"
' Else
' strCriteria = "1=1 "
' strCriteria = strCriteria & _
' BuildIn(Me.lstRSVP, "[rptEventSubRSVP].Report![MyRSVP]", "'")
' End If
'
The issue is that the MYRSVP field called here is on the subreport and in the control source for the subreport query. The above intial code needs to use this build in for the subreport query criteria, but I am not sure how to do that.
Can anyone help me make sense of this minor craziness?
Thanks!
misscrf
It is never too late to become what you could have been ~ George Eliot