Solved printed report log (1 Viewer)

YYYY

Member
Local time
Yesterday, 20:48
Joined
Apr 21, 2020
Messages
39
I would like to save a log when a report as last printed.
how do you add vba to a report that if printed
update ReportPritedLog?

I can't figure out which event it is.
Thanks!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:48
Joined
Aug 30, 2003
Messages
36,124
You can easily add code after the OpenReport line. Or are you talking if they print it after it's opened in preview mode? I'm not sure how to catch that offhand.
 

HalloweenWeed

Member
Local time
Yesterday, 20:48
Joined
Apr 8, 2020
Messages
213
Do you want a text, spreadsheet, or db table log?
Here's what I would do for a text log:
1. Make a text file (it can be empty).
2. Use a print button with code like this:
Code:
Private Sub Print_But_Click()
On Error GoTo Err_Handler

Dim intFileNo As Integer
Dim txtFileName As String, LogMsg As String

    txtFileName = "\YourFilePath\"
    txtFileName = txtFileName & "YourFileName.txt"

'open text log file for append usage
    intFileNo = FreeFile()
    Open txtFileName For Append As #intFileNo
'Log date, time, and Windows UserName
    LogMsg = Format(Date) & " " & Format(Time) & ", User: " & Environ("UserName")
'carriage return/linefeed
    LogMsg = LogMsg & Chr(13) & Chr(10)
'Log whatever other data you want
    LogMsg = LogMsg & "YourDataChange = " & Your Field
'carriage return/linefeed
    LogMsg = LogMsg & Chr(13) & Chr(10)
...

'When done making LogMsg:
'carriage return/linefeeds (and/or anything else you want) to delineate between logging sessions
        LogMsg = LogMsg & Chr(13) & Chr(10) & Chr(13) & Chr(10) & Chr(13) & Chr(10)
        Print #intFileNo, LogMsg
    Close intFileNo                                                     'close text log file

DoCmd.RunCommand acCmdPrint

ExitSub:
    Exit Sub

Err_Handler:
    If Err.Number = 55 Then Resume Next                             'if text file already open
    If Err.Number = 75 Then
        MsgBox "Error opening text log file for logging. Logging failed."
        Resume Next                                                 'if text file open fails
    End If
    If Err.Number = 52 Then Resume Next                             'if text file write fails
    MsgBox ("Error #" & Err.Number & ": " & Err.Description)
    Resume ExitSub

End Sub
 
Last edited:

Isaac

Lifelong Learner
Local time
Yesterday, 17:48
Joined
Mar 14, 2017
Messages
8,777
One policy I once implemented in a few Access databases was to pretty much skip entirely the concept of on-screen report viewing, instead exporting everything to PDF and opening it. Most users love PDFs anyway, but the nice thing about that is you can add the "as of" (print)-date on the report, thus forever preserving it on the PDF. And that is priceless due to users' habits of emailing reports back and forth and then endlessly trying to argue and troubleshoot over "why does this report show ___x", most of which is solved if everyone viewing the report is forced to know the as-of print date. Which I feel is the root problem you are kind of solving for.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:48
Joined
Aug 30, 2003
Messages
36,124
Most of my reports go to preview but I have the date in the page footer, so if the user decides to print it the as-of date is there.
 

Isaac

Lifelong Learner
Local time
Yesterday, 17:48
Joined
Mar 14, 2017
Messages
8,777
Yeah I guess that works too
 

YYYY

Member
Local time
Yesterday, 20:48
Joined
Apr 21, 2020
Messages
39
One policy I once implemented in a few Access databases was to pretty much skip entirely the concept of on-screen report viewing, instead exporting everything to PDF and opening it. Most users love PDFs anyway, but the nice thing about that is you can add the "as of" (print)-date on the report, thus forever preserving it on the PDF. And that is priceless due to users' habits of emailing reports back and forth and then endlessly trying to argue and troubleshoot over "why does this report show ___x", most of which is solved if everyone viewing the report is forced to know the as-of print date. Which I feel is the root problem you are kind of solving for.
I guess this is my only option if I want an accurate log.
I"ll use the docmd.runsql "insert into log...."values(date...
to log the print date
Thanks for your hep!
 

Users who are viewing this thread

Top Bottom