473,394 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

create PDF and mail in one action

Probably just a minor detail, because I almost got it working.
Creating the PDF file goes fine, thanks to all the bas****-files from
http://www.mvps.org/access/. Also the mail functionality goes fine.
The only problem is that I need two buttons to make it work; one to
create the PDF file and one to fetch the recently created PDF and
attach it to en e-mail.

To create the PDF I use this code (and all the other files from "The
Access Web"):

Sub Button_Click()
PrintPDF "filename" , "reportname"
End Sub

***********
Function PrintPDF(strPDFnaam As String, strRapport As String)

ChangeToAcrobat
Call SetRegValue(HKEY_CURRENT_USER, "Software\Adobe\Acrobat
PDFWriter", "PDFFileName", strPDFnaam)
DoCmd.OpenReport strRapport, acViewNormal
ResetDefaultPrinter

End Function
***********

To mail with attachment I use the code from Microsoft at
http://support.microsoft.com/?id=209948 which I rewrote to fit my
needs.

Sub Button_Click()

Set all "str..." Strings

SendMessage strFrom, strTo, strCC, strBCC, strSubject, strBody,
strAttachment, Preview
End Sub

***********
Function SendMessage(Optional strFrom, Optional strTo, Optional strCC,
Optional strBCC, Optional strSubject, Optional strBody, Optional
strAttachment, Optional Preview As Boolean)

Dim objOutlook As Outlook.Application
Dim objOutlookNs As Outlook.NameSpace
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookNs = objOutlook.GetNamespace("MAPI")
objOutlookNs.Logon

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
.SentOnBehalfOfName = strFrom
Set objOutlookRecip = .Recipients.Add(strTo)
objOutlookRecip.Type = olTo

If strCC <> "" Then
Set objOutlookRecip = .Recipients.Add(strCC)
objOutlookRecip.Type = olCC
End If

If strBCC <> "" Then
Set objOutlookRecip = .Recipients.Add(strBCC)
objOutlookRecip.Type = olBCC
End If

.Subject = strSubject
.Body = strBody & vbCrLf & vbCrLf

If strAttachment <> "" Then
Set objOutlookAttach = .Attachments.Add(strAttachment)
End If

For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next

If Preview = True Then
.Display
Else
.Send
strMessage = "The message has been send to " & strTo
strTitle = "Outlook"
intStyle = vbInformation
MsgBox strMessage, intStyle, strTitle
End If

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing

Exit Function
***********

What do I need to do to get it working in just one action? If I put
both functions behind one button, I only get the PDF, but it doesn't
get send. I tried to let the code wait or even sleep while creating
the PDF, but that didn't help.
Nov 12 '05 #1
0 1453

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RiGGa | last post by:
Hi, I am creating a form in php and one of the fields will be prompting the user to enter a time in the HH:MM format, is there anyway using php to create an input mask so it appears as __:__ ...
9
by: joealey2003 | last post by:
Hi all... A simple mail example like... <? mail("acco...@yahoo.com","Subject of Message","Message"); ?> does not work to yahoo or spymac.com, but the same works to gmail and other servers.
2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
0
by: | last post by:
A mail sent by you has been identified as suspicious by MailMonitor for Exchange. Event: infection Action: Message quarantined Message...
20
by: Hemant Shah | last post by:
Folks, I am using DB2 UDB 8.2 on AIX 5.1. How large of a bufferpool can you create? I tried to create a 4GB bufferpool db2 complained that is cannot allocate enogth memory. I have 16GB on this...
0
by: Wouter | last post by:
Probably just a minor detail, because I almost got it working. Creating the PDF file goes fine, thanks to all the bas****-files from http://www.mvps.org/access/. Also the mail functionality goes...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
13
Nert
by: Nert | last post by:
hello every one, i need help.. how can i use the mail() funtion in php? when ever i execute the mail function i continuesly receive this error message: what do i need to do in order for me...
2
by: Hughesie11 | last post by:
Im trying to post from a form to send an email, im using CDONTS ( I have to as it will be running on NT4), the object appears to get created fine, however the email is not sending, its generates 3...
4
by: matthewroth | last post by:
I am at my wits end. I have this code (posted below) with a send email button, which is in theory supposed to send just that page. The problem, that i can't resolve, is that is sends an email for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.