I am trying to use one report for two queries instead of creating additional reports for additional queries. Essentially, all I want to do is use an If...then...else statement in my report to set which query the report is based on. In the Report_Open section of code for my report I have the following VBA code:
Dim qdf As QueryDef
Set dbsReport=CurrentDb
If [forms]![formname]![fieldname]="(string)" then
Set qdf=dbsReport.QueryDefs("queryname1"
qdf.Parameters("(query specific parameters)"
Set rstReport=qdf.OpenRecordset()
Else
Set qdf=dbsReport.Querydefs("queryname2"
Set rstReport=qdf.OpenRecordset()
End if
My queryname2 is the same query as queryname1 without parameters, if that matters. My problem with this code is that even when the if...then statement is not satisfied, it is still carried out, which returns no data. I know this, because I display a message box on the No Data event and I have confirmed that my queryname2 has data. It seems that the ...else portion of my statement is never carried out. Any ideas on how to fix this? Thanks in advance!!
Dim qdf As QueryDef
Set dbsReport=CurrentDb
If [forms]![formname]![fieldname]="(string)" then
Set qdf=dbsReport.QueryDefs("queryname1"
qdf.Parameters("(query specific parameters)"
Set rstReport=qdf.OpenRecordset()
Else
Set qdf=dbsReport.Querydefs("queryname2"
Set rstReport=qdf.OpenRecordset()
End if
My queryname2 is the same query as queryname1 without parameters, if that matters. My problem with this code is that even when the if...then statement is not satisfied, it is still carried out, which returns no data. I know this, because I display a message box on the No Data event and I have confirmed that my queryname2 has data. It seems that the ...else portion of my statement is never carried out. Any ideas on how to fix this? Thanks in advance!!