I create many reports using VBA in MS Access. I want to produce these as PDF files to specific folders that are based on some of the data in the report. Currently, I am just printing the reports using the Adobe printer which opens the print dialog. I have to choose the folder and click save on each report. I want to produce the PDFs without having to perform this step.
I have the Adobe SDK but can't put my fingers on a reference for VBA. Any help would be appreciated!
Thanks
Walter
Here is the code:
Public Function ExportScorecards()
Dim oldname As String
Dim newname As String
Dim existingfile As String
Dim inputdir
Dim rs As DAO.Recordset
Dim strContractID As String
On Error Resume Next
Set rs = CurrentDb.OpenRecordset("Select ContractID from GETID;")
rs.MoveFirst
While Not rs.EOF
gstrContractID = rs!ContractID
gstrExistingScorecard = Dir(gstrScorecardFilePath & "" & gstrContractID & ".pdf")' *** This is to delete the existing pdf file if it exists
Do While Len(gstrExistingScorecard) > 0
Kill gstrScorecardFilePath & "" & gstrExistingScorecard
gstrExistingScorecard = Dir
Loop' *** Print the report, Report has adobe pdf as specific printer
DoCmd.OpenReport gstrScorecardReportName, acNormal, , "ContractID='" & gstrContractID & "' "' *** Delay for completion of adobe printing
WaitAwhile (3)
' *** File locations
oldname = gstrScorecardFilePath & "" & gstrReportPDFStaticName _
: newname = gstrScorecardFilePath & "" & gstrContractID & ".pdf"' *** function for moving and changing the file name
Name oldname As newname
rs.MoveNext
Wend
Set rs = Nothing
End FunctionPublic Function WaitAwhile(seconds As Integer)
On Error GoTo wait_err
Dim tmp As Variant
tmp = Now
Call SysCmd(acSysCmdInitMeter, "Waiting " & seconds & " Seconds...", seconds)
Do While Now < tmp + (seconds / 24 / 60 / 60)
Call SysCmd(acSysCmdUpdateMeter, DateDiff("s", tmp, Now))
DoEvents
Loop
wait_res:
Call SysCmd(acSysCmdClearStatus)
Exit Function
wait_err:
MsgBox Error & " " & Err.Description, 0, "WaitAwhile Error!"
Resume wait_res
End Function