Setting RecordSource with command button

  • Thread starter Thread starter Jason M Canady
  • Start date Start date
J

Jason M Canady

I would like to set the record source of my report using a command button.
Can this be done? I have several queries containing all of the same field
names, and I would like to use one report for all of these... I cannot seem
to change the Record Source however...
Any assistance would be appreciated.

Jason M Canady
 
Jason,
I suppose you have some method for the user to select the query wanted,
(lets say a combo box listing (as text) all the possible recordsources for
the report).
If so, delete the Record Source of the report.

Then code the Report's Open Event:
Me.RecordSource = Forms!FormName!ComboName

Code a Command button on this form to open the report.

You could also use an option group on the form, in which case the group will
get a number value when you make a selection.
In this case code the Report Open event:

Dim strSource as String
Select Case Forms!FormName!OptionGroupName
Case is =1
strSource = "QueryName1"
Case is = 2
strSource = "QueryName2"
Case is = 3
etc.
Case Else
strSource = "SomeQueryName"
End Select
Me.RecordSource = strSource

Please note that the form must be open when you run the report.
close the form in the Report's Close event:
DoCmd.Close acForm, "FormName"
 
Fred, thanks for the valuable info. I will take a look at implimenting what
you have suggested, especially as my database gets more and more complex.
In playing around with the reports and quieries a bit more this afternoon I
discovered that I can access the filter property thus enableing me to use 1
query and 1 report for all 20 reports that I need to generate!

I do not think that this will work very well however, when the db gets
larger and I need to run more complex reports... Your suggestion will work
great for that! Thanks,

Jason
 
Back
Top