Eljefegeneo
Still trying to learn
- Local time
- Today, 10:04
- Joined
- Jan 10, 2011
- Messages
- 902
PDF file problem
I have some code that does two things. It sends a copy of a report via email as a pdf flie and (2) then saves the same report as a pdf file to a folder. Unfortunately I cannot figure out how not to have the pdf file open. The DB is on several different computers and the Adobe Reader always seems to open up, sometimes placing the pdf file in the forefront so the user has to find the email program, send the email, and close the pdf file. .
The main problem seems to be that when saving the report as a pdf file, it automatically opens up the pdf file using Adobe Reader after the save. While this would seem to be an Adobe problem, searching for the answer only produces "help" that probably only an advanced programmer might understand. So, I thought perhaps there is some VBA code that would close the pdf file or prevent it from opening.
I first open the report with the following:
DoCmd.OpenReport "rptContractClient", acViewReport, , "[SequenceNumber] = " & Me![SequenceNumber], , "A"
Then I save the report with:
DoCmd.OutputTo acOutputReport, MyRpt, acFormatPDF, MyPath & MyFileName, True
Finally I send it via email using:
DoCmd.SendObject acSendReport, "rptContractClient", acFormatPDF, Forms!frmContracts.Email, Nz(Forms!frmContracts.ECC, ""), Nz(Forms!frmContracts.EBCC, ""), "Contract for" & " " & [AltStationName], Format(Date, "Long Date") & Chr(10) & MsgSt
Individually the above codes function fine. But the darn pdf file always opens and I have to manually close it. Not a big problem if only one record is being saved and sent, but if I want to do it with for many reports at the same time using some loop type code, it would result in too many pdf files open.
So, can I execute the save without opening the pdf file, or is there a fairly simple way of closing the pdf file with vba?
I have some code that does two things. It sends a copy of a report via email as a pdf flie and (2) then saves the same report as a pdf file to a folder. Unfortunately I cannot figure out how not to have the pdf file open. The DB is on several different computers and the Adobe Reader always seems to open up, sometimes placing the pdf file in the forefront so the user has to find the email program, send the email, and close the pdf file. .
The main problem seems to be that when saving the report as a pdf file, it automatically opens up the pdf file using Adobe Reader after the save. While this would seem to be an Adobe problem, searching for the answer only produces "help" that probably only an advanced programmer might understand. So, I thought perhaps there is some VBA code that would close the pdf file or prevent it from opening.
I first open the report with the following:
DoCmd.OpenReport "rptContractClient", acViewReport, , "[SequenceNumber] = " & Me![SequenceNumber], , "A"
Then I save the report with:
DoCmd.OutputTo acOutputReport, MyRpt, acFormatPDF, MyPath & MyFileName, True
Finally I send it via email using:
DoCmd.SendObject acSendReport, "rptContractClient", acFormatPDF, Forms!frmContracts.Email, Nz(Forms!frmContracts.ECC, ""), Nz(Forms!frmContracts.EBCC, ""), "Contract for" & " " & [AltStationName], Format(Date, "Long Date") & Chr(10) & MsgSt
Individually the above codes function fine. But the darn pdf file always opens and I have to manually close it. Not a big problem if only one record is being saved and sent, but if I want to do it with for many reports at the same time using some loop type code, it would result in too many pdf files open.
So, can I execute the save without opening the pdf file, or is there a fairly simple way of closing the pdf file with vba?