Print to Docusign VBA (1 Viewer)

jsdba

Registered User.
Local time
Today, 06:02
Joined
Jun 25, 2014
Messages
165
Hi Experts,

I'm looking for a way to send a document to docusign print driver. the code below when it works launches docusign print driver with the document in the print queue. The code below works inconsistently. sometimes it works, sometimes it doesn't work. if i step thru the code it works every time. I've adjusted the pause, trying different time interval but outcome is still inconsistent. I need a better way to do this. if anyone has experience doing this i would really appreciate some help.

Code:
Private Sub DocuSign(strPathFile)
Dim dfltPrinter As String
Dim newPrinter As New WshNetwork

'Get the name of the default printer
dfltPrinter = Me.Printer.DeviceName
'Set the default to the new printer
'USE YOUR ACTUAL PRINTER NAME BELOW
newPrinter.SetDefaultPrinter ("Print to DocuSign")
'Pause
Sleep 2000
'Print the pdf document
'USE YOUR ACTUAL DOCUMENT NAME & PATH BELOW
Call ShellExecute(Me.hwnd, "print", strPathFile, "", 0, SW_SHOWNORMAL)
'Pause
Sleep 2000 'wait for 2 seconds - increase this if the code doesn't appear to work
'kill the acrobat process, if it is still running
KillProcess ("acrobat")
'Pause
Sleep 2000
'Set the printer back to the original default
newPrinter.SetDefaultPrinter (dfltPrinter)
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:02
Joined
Feb 28, 2001
Messages
27,191
I've adjusted the pause, trying different time interval but outcome is still inconsistent.

Just as a thought, try a loop that sleeps for a moment then tests Me.Printer.Device name to see if it has changed yet, and put a safety limit in the loop so that if it takes more than about 20 seconds, pop up a message box warning you.

As ANOTHER thought, sometimes after you do something to an external entity (such as the printer), you need to insert a DoEvents afterwards. A Sleep might not allow a lower priority process to get to the CPU, whereas a DoEvents CERTAINLY allows that. And if I recall correctly, printer drivers are lower execution priority than GUI-level tasks (of which Access is one).
 

June7

AWF VIP
Local time
Today, 02:02
Joined
Mar 9, 2014
Messages
5,474
Following on Doc's comment, I have never used Sleep but have used Do Events without issue. Also Do Loop. Examples.
Code:
        Dim Start As Double
        Start = Timer
        While Timer < Start + 3
            DoEvents
        Wend
 
        Do
            'Wait till the Browser is loaded
        Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
 

Users who are viewing this thread

Top Bottom