email from a form
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!Appt Time, "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
' .Send
End With
rst.Close
Set rst = Nothing
|