Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If...then...else statement in report

Status
Not open for further replies.

medic133

Technical User
Apr 7, 2002
86
US
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!!
 
("string") is set to either "Clinical" or "Internship" depending on a command button a student clicks. Clicking on a command button populates a textbox with either "Clinical" or "Internship". From here the student can click on another command button which is based on a query which has as a parameter based on the value of the above textbox. The report lists several totals from the query. I can easily use this report for the above query. What I would like to do is use the same report for a query that doesn't have the above parameter (in other words a query which totals values for both intership and clinicals-these are paramedic students). This will save me tons of room in my database if I don't have to have double the number of reports.

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top