Logging Windows Print events

I would like to know if it's possible to capture the fact that the contents of a OLE field was printed from the native application being used to view the OLE contents.

Example: A user opens a Word Document from an embedded or linked OLE field, prints that document, and then somewhere in the VBA code for that screen my MS Access app can see that something was just printed and ask the user to enter a few parameters to establish a log that a printed copy was made.

I could just ask every time the screen closed, "Did you pint it?"  Although that's going to get annoying very fast.

Is there anything happening in the bowels of Access or the operating system I could use as a reasonable trigger to ask the user to make a print log?
David SmithsteinCEOAsked:
Who is Participating?
David SmithsteinCEOAuthor Commented:
Jeffrey CoachmanMIS LiasonCommented:
If this can be done from the OS, it is beyond me.

About the best you may be able to do is log this if a user clicks a "Print" button.

It would add the various pieces of info to a table, ...something roughly like this:

Currentdb.execute "INSERT INTO YourTable (Field1, Field2, Field3,...)
VALUES (value1, value2, value3,...)",dbfailonerror

Jeffrey CoachmanMIS LiasonCommented:
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

David SmithsteinCEOAuthor Commented:
Thanks, but that doesn't help me as i'm storing controlled documents, MS Word, .pdf. Excel, anything that is OLE enabled and would like to add a feature that helps the client know if any were printed so obsolete ones can be retrieved when needed.
David SmithsteinCEOAuthor Commented:
Almost, but not quite. Is it possible to query the Operational log of the PrintService?  When I modify the code to look in that folder, I get "0 logs searched" even though I can go into event viewer and see a print job (EventID 307) there from yersterday.

Dim objObject As WbemScripting.SWbemObject
Dim setObjectSet As WbemScripting.SWbemObjectSet
Dim strServer As String
Dim strWQL As String
Dim svcServices As WbemScripting.SWbemServices
Dim varInsertionString As Variant
Dim Counter As Integer

Counter = 0
strServer = "."  ' This computer
Set svcServices = GetObject("winmgmts:\\" & strServer & "\root\cimv2")

strWQL = "SELECT * " & _
         "FROM Win32_NTLogEvent " & _
         "WHERE Logfile = ""Microsoft-Windows-PrintService/Operational"""
Set setObjectSet = svcServices.ExecQuery(strWQL)

For Each objObject In setObjectSet
   ' MsgBox "Category: " & objObject.Category
 If objObject.EventCode = "307" Then
    MsgBox "Found Print Job"
     MsgBox "Time Generated: " & objObject.TimeGenerated
    MsgBox "Time Written: " & objObject.TimeWritten
    Exit Sub
 End If
 Counter = Counter + 1
  '  MsgBox "CategoryString: " & objObject.CategoryString
  '  MsgBox "Computer Name: " & objObject.ComputerName
 '   MsgBox "Data: " & objObject.Data
 '   MsgBox "Event Code: " & objObject.EventCode
  '  MsgBox "Event Identifier: " & objObject.EventIdentifier
 '   For Each varInsertionString In objObject.InsertionStrings
 '       MsgBox "Insertion String: " & varInsertionString
 '   Next
 '   MsgBox "Logfile: " & objObject.Logfile
 '   MsgBox "Message: " & objObject.message
 '   MsgBox "Record Number: " & objObject.RecordNumber
 '   MsgBox "Source Name: " & objObject.SourceName
'    MsgBox "Type: " & objObject.Type
'    MsgBox "User: " & objObject.User

    Set objObject = Nothing
Set setObjectSet = Nothing

Set svcServices = Nothing
MsgBox Counter & " logs searched"
to log all print events over a network look at event ID's

"System 10: " or "System 307: "

best way to use this is to look at SIEM software which you can use to correlate and automate it so each time an event occurs its correlated together
David SmithsteinCEOAuthor Commented:
I was told by a programmer of event log software in England that:

"I think the problem is that the log you're after isn't covered by the eventlog WMI provider, i.e. so far as I'm aware there is no way to get at that log via WMI. This is something that has caused me major headaches and really ticks me off about MS; it goes completely against the spirit of WMI.

There is however another way to get at that log - look up the "Windows Event Log API"

I'll I've been able to find is code on how to post a log to the event log, but nothing to simple read it, and hopefull limit the read based on a date range of just today.
David SmithsteinCEOAuthor Commented:
tested this code and I am able to read event logs on my Windows 7 computer using MS Access 2010
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.