Report to PDF- Can I predefine the filename?

nate

Registered User.
Local time
Yesterday, 17:16
Joined
May 19, 2010
Messages
29
Using Access 2010, I occassionally need to export a report as a PDF file. These are invoices, and I'd like the filenames to be created automatically (CustomerName then Order Number) so that there is consistency.

Has anyone attempted this before, and could point me in the right direction?
 
This should get you started:

DoCmd.OutputTo acOutputReport, "rptBooking", acFormatPDF, GetBEFolder("tblBookings") & strFileName & ".pdf"

The GetBEFolder function gets the path to the back end, which you can replace with your path. strFileName contains a string built previously which contains the specific customer and booking numbers.
 
hi paul

how can i insert WhereCondition in this code?

when i run my report it is wanted a branch id, i think there must be a way to fill branch id field from a specific table
i want to use your code for creating pdf files for each seperate branch

thxx
 
Last edited:
we have WhereCondition parameter at DoCmd.OpenReport method

is there anything like this at DoCmd.OutputTo ??
 
thx paul, i checked your link but i couldnt insert where condition to open the report

i think i need to insert code at below, but i don't know how :confused:
DoCmd.OpenReport "ReportXX", acViewNormal, "", " branch_code =" & rst! branch_code


my whole code is below, could you pls help me, thxx:cool:
---
Private Sub Command1_Click()
Dim dbs As Database
Dim dbsb As Database
Dim rst, rstb
Dim jj As Integer
Dim cik As Integer
Dim myFile As String

qstr = "SELECT * FROM [branch_list] WHERE branch_code<=100"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(qstr)

While Not rst.EOF

cik = 0
myFile = Dir("C:\Documents and Settings\ deneme\" & rst!branch_code & ".pdf", vbDirectory)
Do While Not myFile = vbNullString

myFile = Dir
cik = 1
Loop

DoEvents

If cik = 0 Then

DoEvents
DoCmd.OutputTo acOutputReport, "ReportXX", acFormatPDF, "D:\Profiles\AkinM\My Documents\deneme\" & rst!branch_code & ".pdf"

End If

rst.MoveNext

Wend

rst.Close

End Sub
 
Last edited:
Try it immediately before the OutputTo line. You'd also want to change the acViewNormal to acViewPreview, and perhaps hidden (otherwise the user will see the reports opening and closing). After the OutputTo line you'd want to close the report.
 

Users who are viewing this thread

Back
Top Bottom