C
carls
I am having a small issue automatically saving a created
pdf file through VBA. I want to name the pdf file I am
creating based on a varibale from my code(which i do have
working but it only works correctly 50% of the time).
Sometimes the pdf file saves perfectly and other times it
saves as a file name that is missing anywhere from the
first 3-5 characters. How do i get it to name the file
properly every time? Here is my code sample:
DoCmd.SetWarnings False
Dim rs As Recordset
Dim db As Database
Dim filename As String
Dim pdfname As String
Dim keystrokes As String
Set db = CurrentDb
Set rs = db.OpenRecordset("rsname")
rs.MoveFirst
key1 = "{enter}"
With rs
Do While Not .EOF
filename = rs![ProdNum]
pdfname = filename & ".pdf"
DoCmd.OpenReport "rptname", acViewPreview
sendkeys pdfname, False
sendkeys (key1), False
DoCmd.PrintOut
rs.MoveNext
DoCmd.Close acReport, "rptname", acSaveNo
Loop
End With
DoCmd.SetWarnings True
pdf file through VBA. I want to name the pdf file I am
creating based on a varibale from my code(which i do have
working but it only works correctly 50% of the time).
Sometimes the pdf file saves perfectly and other times it
saves as a file name that is missing anywhere from the
first 3-5 characters. How do i get it to name the file
properly every time? Here is my code sample:
DoCmd.SetWarnings False
Dim rs As Recordset
Dim db As Database
Dim filename As String
Dim pdfname As String
Dim keystrokes As String
Set db = CurrentDb
Set rs = db.OpenRecordset("rsname")
rs.MoveFirst
key1 = "{enter}"
With rs
Do While Not .EOF
filename = rs![ProdNum]
pdfname = filename & ".pdf"
DoCmd.OpenReport "rptname", acViewPreview
sendkeys pdfname, False
sendkeys (key1), False
DoCmd.PrintOut
rs.MoveNext
DoCmd.Close acReport, "rptname", acSaveNo
Loop
End With
DoCmd.SetWarnings True