oxicottin
Learning by pecking away....
- Local time
- Today, 06:27
- Joined
- Jun 26, 2007
- Messages
- 888
Hello, How do I get the VBA below to wait until the .pdf opens and prints before continuing? My reports all stack in order by dates etc and the pdf is in the middle when its supposed to be after the first print. The code in question is marked with HERE.... TO HERE. I tried using DoEvents after the line:
CreateObject("Shell.Application").Namespace(0).ParseName(strSafetyContactPath).InvokeVerb ("Print")
but it seems like it doesn't wait? I also tried sleep for 8 seconds using:
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliSeconds As Long)
And when it gets to the Sleep(8000) Access closes.
CreateObject("Shell.Application").Namespace(0).ParseName(strSafetyContactPath).InvokeVerb ("Print")
but it seems like it doesn't wait? I also tried sleep for 8 seconds using:
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliSeconds As Long)
And when it gets to the Sleep(8000) Access closes.
Code:
Public Sub Print4Days()
Dim strSafetyContactPath As String
'***********************************************************************************************************
'Print Weekly safety hudle cover sheet report
DoCmd.OpenReport "rpt_WeeklySafetyHuddle", acViewNormal
HERE '***********************************************************************************************************
'Print .pdf if textbox is checked if not then move on
'Pdf Documents full path in from txtUnboundSafetyCPath
strSafetyContactPath = Nz(Forms!frm_WeeklySafetyHuddle!txtUnboundSafetyCPath, 0)
If Len(Dir$(strSafetyContactPath)) > 0 Then
SetAttr strSafetyContactPath, vbNormal
'Print the .pdf file
CreateObject("Shell.Application").Namespace(0).ParseName(strSafetyContactPath).InvokeVerb ("Print")
Else
'Do Nothing there wasnt a file just move on
End If
TO HERE '***********************************************************************************************************
'Print Monday - Tuesday SpotCheck Reports
Dim x As Integer
For x = 4 To 3 Step -1
DoCmd.OpenReport "rpt_SpotCheck", , , , , Format(Forms!frm_WeeklySafetyHuddle!txtWeekEnding - x, "Long Date")
DoCmd.Close
Next
'***********************************************************************************************************
'Print Wednesdays Gemba Walk and SpotCheck Reports
DoCmd.OpenReport "rpt_GembaWalk", , , , , Format(Forms!frm_WeeklySafetyHuddle!txtWeekEnding - 2, "Long Date")
DoCmd.OpenReport "rpt_SpotCheck", , , , , Format(Forms!frm_WeeklySafetyHuddle!txtWeekEnding - 2, "Long Date")
'***********************************************************************************************************
'Print Thursdays SpotCheck Report
DoCmd.OpenReport "rpt_SpotCheck", , , , , Format(Forms!frm_WeeklySafetyHuddle!txtWeekEnding - 1, "Long Date")
'***********************************************************************************************************
'Close Acrobat Reader
Call Close_Acrobat_Reader
'Delete the .pdf file
Kill strSafetyContactPath
'***********************************************************************************************************
'Clear a few textboxes on frm_WeeklySafetyHuddle
Forms!frm_WeeklySafetyHuddle.txtUnboundSafetyCPath = ""
Forms!frm_WeeklySafetyHuddle.txtVWIReviewed = ""
Forms!frm_WeeklySafetyHuddle.txtSOCReviewed = ""
Forms!frm_WeeklySafetyHuddle.txtLOTOReviewed = ""
Forms!frm_WeeklySafetyHuddle.chkPrintPaperLift = False
'Set focus to current week button on frm_WeeklySafetyHuddle
Forms!frm_WeeklySafetyHuddle.cmdCurrentFriday.SetFocus
'***********************************************************************************************************
'Completed message box
MsgBox "4 day printout is completed!", vbInformation, "Completed"
End Sub
Last edited: