Sahmara
asked on
Runtime error '2147467261 (80004003)': Automation error invalid pointer
Hello Experts:
I have an AutoExec function called ChangePrinter that captures what the current default printer is (global) and then sets it to a specific printer.
On the Switchboard form, in the on close event, it calls GoDefaultPrinter to change it back to the original printer that Windows was set to prior to the db being opened.
I am able to capture the correct printer name if I uncomment the message box in the code. I am able to get the code (autoexec and the on close) to do what I want without errors if I step line by line. When I open the database, the autoexec code fires off without a hitch. When I try to close out of the Switchboard, I receive the error, "Runtime Error '2147267261 (80004003'): Automation error invalid pointer."
Any suggestions on how to correct this?
Thank you!
I have an AutoExec function called ChangePrinter that captures what the current default printer is (global) and then sets it to a specific printer.
On the Switchboard form, in the on close event, it calls GoDefaultPrinter to change it back to the original printer that Windows was set to prior to the db being opened.
I am able to capture the correct printer name if I uncomment the message box in the code. I am able to get the code (autoexec and the on close) to do what I want without errors if I step line by line. When I open the database, the autoexec code fires off without a hitch. When I try to close out of the Switchboard, I receive the error, "Runtime Error '2147267261 (80004003'): Automation error invalid pointer."
Any suggestions on how to correct this?
Thank you!
Option Compare Database
Option Explicit
Global GBL_Printer As String
Public Function ChangePrinter()
'Set Reference to Windows Script Host Object Model \System32\wshom.ocx.
Dim w As New WshNetwork, p As String
GBL_Printer = Printer.DeviceName 'Gets the default printer
w.SetDefaultPrinter ("ImageMaster")
Set w = Nothing
End Function
Function GoDefaultPrinter()
Dim n As New WshNetwork, p As String
p = GBL_Printer
n.SetDefaultPrinter p
Set n = Nothing
'MsgBox "The original printer was " & GBL_Printer & ".", vbInformation, "Testing"
End Function
ASKER
So that would mean I would input that code into every report in this db? There's over 20 reports.
ASKER
I think I'm receiving this error because it's being executed on the "On Close" event of the switchboard, but it should be in the constants of the Switchboard code "conCmdExitApplication". I'll try there.
No you can set the printer but not reset it
Application.Printer = "CutePDF Writer"
On the Switchboard Open or Load event should be sufficient. You should not need to reset it as it is only set for the current Access instance.
Cheers, Andrew
Application.Printer = "CutePDF Writer"
On the Switchboard Open or Load event should be sufficient. You should not need to reset it as it is only set for the current Access instance.
Cheers, Andrew
Sorry missed a bit of the code
Application.Printer = Application.Printers("Cute PDF Writer")
Cheers, Andrew
Application.Printer = Application.Printers("Cute
Cheers, Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lol, leave it to me to make it WAY more complicated than necessary. Your solution is simple and it's working like a charm after testing extensively. Thanks!
Cheers, Andrew
Open in new window