C
Clyde
Prior to the following code snippet I have set the application printer to an
Adobe PDF printer, which when rptInv is opened will create a pdf file in a
know directory.
After which I would like to rename the file from it's generic name to a
specific name (InvNo12345-00001) as an example.
All of this occurs in a loop of email invoice customers.
Ultimately my goal is to create all of the invoices then loop through the
files and send the invoices as pdf attachments via Outlook (with Redemption
software to overcome the security issues). The code works everytime if you
step through in debug, (time enough for the file to be created!)
PROBLEM: rptInv.pdf file has not finished being created before the rename
code starts the renaming process. (File not found error). I have made
several attempts to insure the file creation is finished ie checking if there
is a file name (strPDFDone <> "". I used the n count to see how long it took
and it varies greatly. This code works occasionally but is unreliable. HOW
DO I INSURE THE FILE HAS BEEN CREATED BEFORE THE CODE PROCEEDS?
'send the report to file by using the PDF printer whose
properties have
'been set to c:\VEEmails. The file name will be
c:\veemails\rptInv.pdf
DoCmd.OpenReport "rptInv"
Reports("rptInv").Visible = False
DoCmd.Close acReport, "rptInv", acSaveNo
'DoEvents
'rename the file
'first make sure the pdf doc creation is finished
n = 0
Do Until strPDFDone <> ""
'returns "" if file not found
strPDFDone = Dir(mstrPDFDir & "rptInv.pdf")
n = n + 1
Loop
MsgBox "count = " & CStr(n)
strPDFDone = ""
strFile = mstrPDFDir & "INV" & !InvNo & ".pdf" 'desired new name
Name mstrPDFDir & "rptInv.PDF" As strFile
Adobe PDF printer, which when rptInv is opened will create a pdf file in a
know directory.
After which I would like to rename the file from it's generic name to a
specific name (InvNo12345-00001) as an example.
All of this occurs in a loop of email invoice customers.
Ultimately my goal is to create all of the invoices then loop through the
files and send the invoices as pdf attachments via Outlook (with Redemption
software to overcome the security issues). The code works everytime if you
step through in debug, (time enough for the file to be created!)
PROBLEM: rptInv.pdf file has not finished being created before the rename
code starts the renaming process. (File not found error). I have made
several attempts to insure the file creation is finished ie checking if there
is a file name (strPDFDone <> "". I used the n count to see how long it took
and it varies greatly. This code works occasionally but is unreliable. HOW
DO I INSURE THE FILE HAS BEEN CREATED BEFORE THE CODE PROCEEDS?
'send the report to file by using the PDF printer whose
properties have
'been set to c:\VEEmails. The file name will be
c:\veemails\rptInv.pdf
DoCmd.OpenReport "rptInv"
Reports("rptInv").Visible = False
DoCmd.Close acReport, "rptInv", acSaveNo
'DoEvents
'rename the file
'first make sure the pdf doc creation is finished
n = 0
Do Until strPDFDone <> ""
'returns "" if file not found
strPDFDone = Dir(mstrPDFDir & "rptInv.pdf")
n = n + 1
Loop
MsgBox "count = " & CStr(n)
strPDFDone = ""
strFile = mstrPDFDir & "INV" & !InvNo & ".pdf" 'desired new name
Name mstrPDFDir & "rptInv.PDF" As strFile