I cleaned up the code and marked out the changes to the PDF however I still get the error on line: DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypdfpath, False
Code:
Function makeHTMLPDF(controlYear As Control, controlType As Control, controlState As Control, controlArea As Control, frm1 As String)
'*** 8 is ACT - as this has no area it will not need a pdf and use the NSW one
For i = 0 To controlState.ListCount - 1
controlState = controlState.Column(0, i)
If controlState.Column(0) <> 8 Then
Debug.Print controlState.Column(1) & " keep "
controlArea.Requery
For a = 0 To controlArea.ListCount - 1
controlArea = controlArea.Column(0, a)
strSQL = "SELECT tblShows.ID, tblShows.ShowName, tblShows.Blurb, tblShowTour.DateTouringFrom, tblShowTour.DateTouringUntil, tblShowTour.TypeID, tblShowTour.AreasID, tblShowTour.YearID " & vbCrLf & _
"FROM tblYear INNER JOIN (tblType INNER JOIN (tblTerms INNER JOIN (tblStates INNER JOIN (tblShows INNER JOIN (tblAreas INNER JOIN tblShowTour ON tblAreas.ID = tblShowTour.AreasID) ON tblShows.ID = tblShowTour.ShowsID) ON tblStates.ID = tblAreas.StatesID) ON tblTerms.ID = tblShowTour.TermsID) ON tblType.ID = tblShowTour.TypeID) ON tblYear.ID = tblShowTour.YearID " & vbCrLf & _
"WHERE (((tblShowTour.TypeID)=" & controlType.Column(0) & ") AND ((tblShowTour.AreasID)=" & controlArea.Column(0) & ") AND ((tblShowTour.YearID)=" & controlYear.Column(0) & "));"
If controlArea.Column(5) = True Then
'Debug.Print "skipped PDF for " & controlArea.Column(1)
Else
If Dir("C:\" & controlYear.Column(1) & "_SPT_WEBSITE\Tour_" & controlType.Column(2) & "\PDF_" & IIf(controlState.Column(0) = 8, "NSW", controlState.Column(1)) & "\", vbDirectory) = "" Then
MkDir ("C:\" & controlYear.Column(1) & "_SPT_WEBSITE\Tour_" & controlType.Column(2) & "\PDF_" & controlState.Column(1) & "\")
End If
DoCmd.OpenReport "rptPrintOut", acViewReport, strSQL, ""
DoCmd.SelectObject acReport, "rptPrintOut"
If Reports("rptPrintOut").Report.txtCount < 40 Then
'Reports("rptPrintOut").Report.ReportHeader.Height = 979
'Reports("rptPrintOut").Report.GroupHeader0.Height = 800
'Reports("rptPrintOut").Report.GroupHeader1.Height = 473
'Reports("rptPrintOut").Report.Term1.Top = 300
'Reports("rptPrintOut").Report.Text61.Top = 313
Else
'Reports("rptPrintOut").Report.ReportHeader.Height = 313
'Reports("rptPrintOut").Report.GroupHeader0.Height = 300
'Reports("rptPrintOut").Report.GroupHeader1.Height = 273
'Reports("rptPrintOut").Report.Term1.Top = 0
'Reports("rptPrintOut").Report.Text61.Top = 0
End If
mypdfpath = "C:\" & controlYear.Column(1) & "_SPT_WEBSITE\Tour_" & controlType.Column(2) & "\PDF_" & IIf(controlState.Column(0) = 8, "NSW", controlState.Column(1)) & "\" & Nz(Reports!rptPrintOut.Caption, "EDIT") & ".pdf"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypdfpath, False
DoCmd.Close acReport, "rptPrintOut"
End If
Next
End If
Next
End Function