email from Access

T

tim johnson

I have the procedure below to email a patient using
records from a form attached to a table.

Everything works fine up to the point where it opens
Outlook Express and populate the fields. However, the
mail is not being sent even though everything is the way
it should be.

When I click the Send button in Outlook the email
disappears from the screen. The email is just not being
sent.

Any suggestion.

Dim patEmail As String ' email of patient from
tblPatient
Dim patName As String 'patient name from tblPatient
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim apTime As Variant 'appointmrnt time taken
from form
Dim apDate As Date ' appointment date taken
form form

'Get email address and patient name from tblPatient
Set rst = New ADODB.Recordset
Set cnn = CurrentProject.Connection
strSQL = "SELECT Email, FName, LName, MI FROM
tblPatient " & _
"WHERE PatientID = " & Forms!frmAppointment!
frmAppointmentSub!PatientID
rst.Open strSQL, cnn, adOpenKeyset, , adCmdText

patEmail = rst!Email
patName = rst!FName & " " & rst!MI & " " & rst!LName
apTime = Format(Forms!frmAppointment!
frmAppointmentSub!ApptTime, "h:mm AM/PM")
apDate = Forms!frmAppointment!ApptDay


' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")


' Create the e-mail message
Set objOutlookMsg = objOutlook.CreateItem
(olMailItem)
patEmail = rst!Email

With objOutlookMsg
' Add the To
recipient(s) to the e-mail message
Set objOutlookRecip
= .Recipients.Add(patEmail)

objOutlookRecip.Type = olTo

' Set the Subject,
Body, and Importance of the e-mail message.
.Subject = "Dental
Appointment"
.Body = "Dear " &
patName & ":" & _
vbCr & vbCr & "This
is a you of you dental appointment scheduled for " &
Format(apDate, "dddd, mmmm d, yyyy") & " at " & apTime
& "." & _
vbCr & vbCr & "If
you are unable to keep the appointment please call me at
(800) 555 8270" & _
vbCr & vbCr
& "Sharon"
.Importance =
olImportanceHigh 'High importance
.Display

End With

rst.Close
Set rst = Nothing
 
C

Cheryl Fischer

Tim,

In your post, you have indicated initially that Outlook Express opens but
later refer to Outlook. The code you have provided should work ok with
Outlook but not Outlook Express. Can you confirm which email product you
are using?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top