RTF Export with criteria

G

Guest

Your expert advise would be so appreciated in the following matter.

I need to save a report as an RTF file. That's not a problem for the user to
do in Preview mode of the report. Simply select File | Export | Type is RTF
... etc. and save the file to the proper name and directory. However, I have
now secured the database (via the startup options) to disallow the user to
make changes and open the database. This also eliminates the "Export" option
in the menu.

I could export the file to RTF using code (as shown below), but it ignores
my criteria. Is there another way to do this?


MyCODE:

strWhere = (misc. criteria information)

If MsgBox("Do you want to export this report to Word?", vbYesNo) = vbYes Then
DoCmd.OutputTo acReport, stDocName, acFormatRTF, "C:\Swifter\test.rtf",
True
Else
DoCmd.OpenReport stDocName, acPreview, , strWhere
End If
 
A

Allen Browne

Use a public string to filter the report:

1. In a standard module (through Modules tab of Database window), in the
General Declaration section (top of module,with Option statements), declare
a public string variable:

Public gstrReportFilter As String

2. In the Open event procedure of the report, if the public string contains
something then apply it to the Filter of the report, and reset the string:

If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If

3. In the code that opens your report, set the filter string before opening
or exporting the report:

gstrReportFilter = "misc.[criteria information]"
DoCmd.OutputTo acReport, stDocName, acFormatRTF, "C:\Swifter\test.rtf",
 
G

Guest

Thank you for your response Allen. It works!!

CS


Allen Browne said:
Use a public string to filter the report:

1. In a standard module (through Modules tab of Database window), in the
General Declaration section (top of module,with Option statements), declare
a public string variable:

Public gstrReportFilter As String

2. In the Open event procedure of the report, if the public string contains
something then apply it to the Filter of the report, and reset the string:

If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If

3. In the code that opens your report, set the filter string before opening
or exporting the report:

gstrReportFilter = "misc.[criteria information]"
DoCmd.OutputTo acReport, stDocName, acFormatRTF, "C:\Swifter\test.rtf",
 

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