Report with variable recordsources

  • Thread starter Thread starter Kerstin Schiebel
  • Start date Start date
K

Kerstin Schiebel

Hi,

I want to open a report with different queries.
In a form the user can choose a department from a combobox.
The name of the query will be created in a vba script e.g. MEWE_Summe pro
KST oder T-Lab_Summe pro KST

But it does not work. After opening the report (PoF) a false recordsource is
inscribed (= the original recordsource from
creating the report). If I delete the recordsource in the report I get an
error message.

----------------------
AbfrageName = Forms![Hauptmenü]![Abteilung] & "_Summe pro KST"

stDocName = "PoF"
DoCmd.OpenReport stDocName, acPreview, AbfrageName, LinkCriteria
--------------------

The content of AbfrageName is correct, but it was not used during opening
the report.
Could anybody tell me what goes wrong?

Thanks
Kerstin
 
Got this one from Fred
You can also use just one report for both tables, by simply
deleting the recordsource and leaving it blank.
Then code the Report Open event to set it's recordsource
there, according to a user selected value on a form:
If forms!FormName!OptionGroupName = 1 Then
Me.RecordSource = "Table1"
Else
Me.RecordSource = "Table2"
End If
The form would have to be open when the report is run.

Jim
 
Hi Jim/Chris/Fred,

thanks a lot. This way works for me.

Bye
Kerstin

Got this one from Fred
You can also use just one report for both tables, by simply
deleting the recordsource and leaving it blank.

....
 
Back
Top