Hi All,
I am trying to create a macro to export a report to pdf multiple times for a whole series of different records. The report (rptQryS) is essentially a template which contains different information depending on which record of a form (frmCompany) is selected.
I've had a go with the macro builder but haven't got very far as I'm new to all of this.
This is what I have so far:
Many thanks in advance.
I am trying to create a macro to export a report to pdf multiple times for a whole series of different records. The report (rptQryS) is essentially a template which contains different information depending on which record of a form (frmCompany) is selected.
I've had a go with the macro builder but haven't got very far as I'm new to all of this.
This is what I have so far:
'------------------------------------------------------------
' ReportGenerationMacro
'
'------------------------------------------------------------
Function ReportGenerationMacro()
On Error GoTo ReportGenerationMacro_Err
DoCmd.OpenForm "frmCOMPANY", acNormal, "", "", , acNormal
DoCmd.Save acForm, "frmCOMPANY"
DoCmd.RunMacro "Repeat", 3, ""
ReportGenerationMacro_Exit:
Exit Function
ReportGenerationMacro_Err:
MsgBox Error$
Resume ReportGenerationMacro_Exit
End Function
'------------------------------------------------------------
' ReportGenerationMacro_Repeat
'
'------------------------------------------------------------
Function ReportGenerationMacro_Repeat()
On Error GoTo ReportGenerationMacro_Repeat_Err
DoCmd.OutputTo acOutputReport, "rptQryS", "PDFFormat(*.pdf)", "\\Computer\x\y\z\REPORT\" & Forms!frmCompany!TradingName & ".pdf", False, "", , acExportQualityPrint
DoCmd.OpenForm "frmCOMPANY", acNormal, "", "", , acNormal
DoCmd.SearchForRecord acForm, "frmCOMPANY", acNext, ""
DoCmd.Save acForm, "frmCOMPANY"
DoCmd.Requery ""
ReportGenerationMacro_Repeat_Exit:
Exit Function
ReportGenerationMacro_Repeat_Err:
MsgBox Error$
Resume ReportGenerationMacro_Repeat_Exit
End Function
This is currently giving me an error - "an expression argument 3 has an invalid value". Does anyone have any advice or perhaps there is a better way of doing this?' ReportGenerationMacro
'
'------------------------------------------------------------
Function ReportGenerationMacro()
On Error GoTo ReportGenerationMacro_Err
DoCmd.OpenForm "frmCOMPANY", acNormal, "", "", , acNormal
DoCmd.Save acForm, "frmCOMPANY"
DoCmd.RunMacro "Repeat", 3, ""
ReportGenerationMacro_Exit:
Exit Function
ReportGenerationMacro_Err:
MsgBox Error$
Resume ReportGenerationMacro_Exit
End Function
'------------------------------------------------------------
' ReportGenerationMacro_Repeat
'
'------------------------------------------------------------
Function ReportGenerationMacro_Repeat()
On Error GoTo ReportGenerationMacro_Repeat_Err
DoCmd.OutputTo acOutputReport, "rptQryS", "PDFFormat(*.pdf)", "\\Computer\x\y\z\REPORT\" & Forms!frmCompany!TradingName & ".pdf", False, "", , acExportQualityPrint
DoCmd.OpenForm "frmCOMPANY", acNormal, "", "", , acNormal
DoCmd.SearchForRecord acForm, "frmCOMPANY", acNext, ""
DoCmd.Save acForm, "frmCOMPANY"
DoCmd.Requery ""
ReportGenerationMacro_Repeat_Exit:
Exit Function
ReportGenerationMacro_Repeat_Err:
MsgBox Error$
Resume ReportGenerationMacro_Repeat_Exit
End Function
Many thanks in advance.