In the code below, the first "DoCmd.OutputTo acOutputReport" directs the use of acFormatPDF for the output format. The second "DoCmd.OutputTo acOutputReport" prompts for the format. Thjs started happening after many tens of executions of the code. Any ideas how to fix this issue?
Code:
Option Compare Database
Option Explicit
Dim I As Integer
Public Function PrintDailyMenu(ChoiceNum As Integer)
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' ChoiceNum 2 > 8 means Sunday > Saturday
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Dim strPDFname As String 'As assigned for each day requested
Dim strPDFPrintQ As String 'As merged by function MergePDFs
Dim strrptName As String 'Varies depending on single or all seven
Dim intChoice As Integer
Dim lngNxtDay As Long 'LoadMenuStrings returns date values for Saturdays
Dim strSearch As String
Dim strTempName As String
Dim dummy As Variant
Dim lngDay As Long
Dim intBegin As Integer 'Start loop here
Dim intEnd As Integer 'End loop here
strPDFname = strPDFMenusFldr & DLookup("Day", "tblWeekDays", "Id = 9") & "Menu" & ".PDF"
strrptName = "rptDailyMenu"
strPDFPrintQ = strPDFMenusFldr & "Print-Q\"
On Error GoTo Err_Handler
'Set the looping values for the selected day(s)
If ChoiceNum = 9 Then
intBegin = 2
intEnd = 8
Else
intBegin = ChoiceNum
intEnd = ChoiceNum
End If
For intChoice = intBegin To intEnd
lngNxtDay = LoadMenuStrings(intChoice)
intBBDay = intChoice - 1
'First, collect the seven days, Sunday through Saturday
strPDFname = strPDFPrintQ & intChoice - 1 & DLookup("Day", "tblWeekDays", "Id = " & intChoice) & "Menu" & ".PDF"
DoCmd.OutputTo acOutputReport, "rptDailyMenu", acFormatPDF, strPDFname, False
'Save the same day, but as a single image/page (Adding the day number at the head of the PDF name)
lngDay = DLookup("F" & intChoice, "tblMenuSheet", "menuID = 1")
strTempName = strFilesFldr & lngDay & "-" & DLookup("Day", "tblWeekDays", "Id = " & intChoice) & "Menu" & ".PDF"
DoCmd.OutputTo acOutputReport, "rptMenuStyle1, acFormatPDF, strTempName, False"
Next intChoice
'Okay, we got what was requested. Now OPEN the print Q where the file(s) can be either opened for inspection or sent to the printer.
Call OpenPDFPrintQ
Exit_Handler:
Exit Function
Err_Handler:
If Err.Number = 2501 Then 'Ignore the 2501 errors
Resume Next
Else
MsgBox "Error " & Err.Number & " in sub ""PrintDailyMenu"" attempting to populate menu lines " & Err.Description
Resume Exit_Handler
End If
End Function
(snip)