save reports to file

damo

Registered User.
Local time
Today, 10:10
Joined
Feb 15, 2000
Messages
15
Hi there,

Ive a client who wants to save reports to a file on their network on the print command.
The reports are standard letters done using Access reports rather than Mail Merge.
Can anyone advise me of the best way to code this?

Ta.
 
Two questions. First, in what format does the client want the file saved? Second what method are they using to open the report and/or print it? Is it a command button from a form or are they opening the report from the database window?

~Abby
 
Thanks for the reply,
They open it from an option on a menu bar, it opens in Print Preview, with another active menu bar from whichg they can then print.
Im not bothered what format It gets daved as,
I was thinking either .TXT or RTF.

Damo.
 
The VB method to save a file in RTF or TXT is fairly simple:

DoCmd.OutputTo acOutputReport, "Report Name", acFormatRTF (or acFormatTXT), strMyReportName, False

You'll need to come up with a naming scheme to set 'strMyReportName' with. See the help file for OutputTo for more information.

The problem is integrating the code into the report. If there is an event that differentiates between printing a report and formatting it for preview, I haven't found it. You could tie this code into the print button on the menu bar. However, if the client selects File, Print, then the script won't be called. Here's the best work around I could come up with. Though if anyone knows a better way please speak up. I'd like to know myself.

Tie the code above into the print button on the menu bar. Also include a public variable (I'll call it bolPrinted for the sake of the example) that is set to true if the script runs. Then, in the reports 'On Close' event do something like:

If bolPrinted = True then
Response = MsgBox ("This report has not been saved to disk. Would you like to save it now?", vbYesNo, "Save File")
If Response = yes then
DoCmd.OutputTo acOutputReport, "Report Name", acFormatRTF, strMyReportName, True
End If
End If

Hope this helps.
~Abby
 
I got it a couple of hours ago, but thanks anyway. I did it like this (for Access 2):
Function MySave ()

Dim mYdB As Database
Dim MySet As Recordset
Dim MyNumber As Double

Set mYdB = CurrentDB()
Set MySet = mYdB.OpenRecordset("tblFileName", DB_OPEN_dynaset)
MySet.lockedits = False

DoCmd Print , , A_Report
MySet.Edit
If MySet!date < Date Then
MyNumber = 1
Else
MyNumber = MySet!Number
End If
MySet!Number = MyNumber + 1
MySet!date = Date
MySet.Update

DoCmd OutputTo A_Report, , A_FORMATRTF, "d:\" & Right$(Str(Day(Date)), 2) & Right$(Str(Month(Date)), 2) & Right$(Str(Year(Date)), 2) & MySet!Number & ".RTF", False

End Function

It works fine, even the date oriented naming convention.
It's behind the FILE, PRINT of a menu bar I created specifically for reports.

Thanks again

Damo.
 

Users who are viewing this thread

Back
Top Bottom