How to output a report that has several record sources toa RTF fil

J

Jeff

Hi everyone,

I'd like to output a report that has several Queries as record sources to a
RTF file. I have a form that has a TextBox on it to let the user choose the
option (Query). The codes in the Click event of a CmdButton look like:

If Me!TextBox = “Food†Then
Reports![ReportName].RecordSource = “qryFoodâ€
ElseIf Me!TextBox = “Drink†Then
Reports![ReportName].RecordSource = “qryDrinkâ€
End If

DoCmd.OutputTo acOutputReport, "ReportName", acFormatRTF, “RTFFileNameâ€

It doesn't work. Is there anything missing? Any help is appreciated.
 
D

Duane Hookom

You can't change the RecordSource property of a closed report. You can
change the SQL of a saved query that is the RecordSource of a report that is
closed.

Dim strSQL as String
If Me!textbox="Food" Then
strSQL = "SELECT * FROM qryFood;"
ElseIf Me!TextBox = "Drink" Then

strSQL = "SELECT * FROM qryDrink;"
End If
CurrentDb.QueryDefs("qryMyReportRS").SQL = strSQL
 
J

Jeff

Hi Duane,

It works perfectly. Thank you very much.
--
Jeff


"Duane Hookom" 來函:
You can't change the RecordSource property of a closed report. You can
change the SQL of a saved query that is the RecordSource of a report that is
closed.

Dim strSQL as String
If Me!textbox="Food" Then
strSQL = "SELECT * FROM qryFood;"
ElseIf Me!TextBox = "Drink" Then

strSQL = "SELECT * FROM qryDrink;"
End If
CurrentDb.QueryDefs("qryMyReportRS").SQL = strSQL

--
Duane Hookom
MS Access MVP
--

Jeff said:
Hi everyone,

I'd like to output a report that has several Queries as record sources to
a
RTF file. I have a form that has a TextBox on it to let the user choose
the
option (Query). The codes in the Click event of a CmdButton look like:

If Me!TextBox = "Food" Then
Reports![ReportName].RecordSource = "qryFood"
ElseIf Me!TextBox = "Drink" Then
Reports![ReportName].RecordSource = "qryDrink"
End If

DoCmd.OutputTo acOutputReport, "ReportName", acFormatRTF, "RTFFileName"

It doesn't work. Is there anything missing? Any help is appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top