Automatically Email using Win2PDf

mcktigger

Registered User.
Local time
Today, 16:24
Joined
Apr 15, 2011
Messages
41
Hi All

I've just installed Win2Pdf which is excellent for creating and e-mailing PDFs. However what I want to do now is automatically save the PDF with the name of the on screen QuoteId and attach to an email. Currently Win2Pdf requires the user to save the PDF and I want to avoid this.

Any help appreciated.

Thanks
 
And I actually should have mentioned DoCmd.SendObject
 
Hi

I'm not the best on VBA. I assume the object name required in the Docmd.OutputTo can be a variable that picks up the QuoteID number from the form. However I'm not sure how to write the code that outputs the report to Win2Pdf.

Can you help?

Many thanks
 
.pdf isn't a native OutputTo format for reports until Access 2007 (which is the reason for the 3rd party Win2PDF), but without knowing how Win2PDF saves the PDF it's hard to say how to remove the prompt.

I've never used Win2PDF.
 
Haven't used this program, however, went to their website and they have a code example how to save without the file dialog box.

http://www.win2pdf.com/doc/

Click on Section on Developer Information,
Programming Environments,
Microsoft Access

If the issue is how to get the code working in your program due to not understanding VBA, then would need to know a bit about your form etc, to help you figure out where to paste and modify the code from the win2pdf website.
 
Hi

Thanks all. I managed to piece it all together. The code below need cleaned up but it work if anyone needs it in future.

Private Sub cmdcomplete_Click()
On Error GoTo Err_cmdcomplete_Click

Dim stDocName As String
Dim stQuoteID As String
Dim stFileName As String
Dim stQuoteFile As String
Dim stEmailAddr As String
Dim prt As Printer
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem

' Get the Printer object for the selected printer.
Set prt = Application.Printers("Win2PDF")

' Set the selected printer as the default printer for this session.
Set Application.Printer = prt

Me.Visible = False
Forms!frmcustomers.Visible = False
stQuoteID = "[QuoteId] = " & Me.[QuoteID]
stQuoteFile = Me.QuoteID
stEmailAddr = Me.ContactEmail
stDocName = "RptCustomerQuote"
stFileName = "C:\Sales\Quotes\" & stQuoteFile & ".pdf"
SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", stFileName
DoCmd.OpenReport stDocName, acNormal, , stQuoteID
Me.cmdclose.Enabled = True
Me.cmdclose.SetFocus
Me.cmdcomplete.Enabled = False
Me.cmdsave.Enabled = False
Me.cmdcancel.Enabled = False

On Error Resume Next
Set oOutlook = GetObject(, "Outlook.Application")
If oOutlook Is Nothing Then Set oOutlook = CreateObject("Outlook.Application")

Set oEmailItem = oOutlook.CreateItem(olMailItem)

With oEmailItem
.Attachments.Add stFileName
.To = stEmailAddr
.Display
End With

Set oEmailItem = Nothing
Set oOutlook = Nothing


Exit_cmdcomplete_Click:
Exit Sub

Err_cmdcomplete_Click:
MsgBox Err.Description
Resume Exit_cmdcomplete_Click

End Sub
 
Hi mcktigger,


Well done - I was about to suggest that to look into using Access 2010 because it has native PDF output facility. But you beat me to it! :)

Nice codes that you have written there, it will sure help others using AC2003 and wish to generate and email PDFs - one to keep for the bookmark!
 
Thanks for the feedback.

A few things to remember if anyone wants to do this.

1. You need to turn on the references to MS Outlook Object Library from within a module.
2. Win2PDF is a chargeable PDF writer. Costs £21 per person for a single user but I think it's worth it.
 

Users who are viewing this thread

Back
Top Bottom