Sending Email from Access (1 Viewer)

patkeaveney

Registered User.
Local time
Today, 20:39
Joined
Oct 12, 2005
Messages
75
Hi

I have searched the forums, and tried to emulate the code samples found but to no avail

Can someome please advise on why my code is not working.

The message box "about to Call Send Email" appears, but then nothing else happens.

I do not get the Msgbox " In Email".

The code below is part of the Add New Student on click event

If SaveAgreedFlag = True Then 'User has replied Yes in Before Update Prodedure
Forms![frmCourseShedulesStudents]![Classes Subform]![txtSaveBox].Value = "Yes"
DoCmd.RunCommand acCmdSaveRecord
MsgBox txtStudentName & vbCrLf & vbCrLf & "Has been Addded to this Course", vbInformation​
Else
If MsgBox("Do you want to Add Student " & vbCrLf & vbCrLf _
& txtStudentName & vbCrLf & vbCrLf _
& "to this Course?", vbYesNo + vbQuestion) = vbYes Then
Forms![frmCourseShedulesStudents]![Classes Subform]![txtSaveBox].Value = "Yes"
DoCmd.RunCommand acCmdSaveRecord
MsgBox txtStudentName & vbCrLf & vbCrLf & "Has been Addded to this Course", vbInformation​
If MsgBox("Do you want to Send a Confirmation Email to" & vbCrLf & vbCrLf _
& txtStudentName & vbCrLf & vbCrLf _
& " ", vbYesNo + vbQuestion) = vbYes Then
MsgBox "about to Call Send Email"
Call SendConfirmationEMail​
End If​
Else​
DoCmd.RunCommand acCmdUndo
Forms![frmCourseShedulesStudents]![Classes Subform]![txtSaveBox].Value = "No"
MsgBox txtStudentName & vbCrLf & vbCrLf & "Has NOT been Addded to this Course", vbInformation​
End If​
End If

Private Sub SendConfirmationEMail()
On Error GoTo Err_SendEMail
MsgBox "in email"

Dim mess_subject As String
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem

SendEMailOK = False

If IsNull(Me.EmailAddress) Then
MsgBox "No Email Address Entered for " & vbCrLf & vbCrLf _
& txtStudentName, vbExclamation
SendEMailOK = False
Exit Sub​
End If

mess_subject = "Confirmation of PAS Training"

mess_body = "Dear " & txtStudentName & vbCrLf & vbCrLf _
& "This is to Confirm your Place on: " & vbCrLf _
& "Course Name " & Forms![frmCourseShedulesStudents].cmbCourses.Text & vbCrLf _
& "Course Schedule " & Forms![frmCourseShedulesStudents].cmbSchedules.Text & vbCrLf _
& "Location " & Forms![frmCourseShedulesStudents].Location.Text

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook

.To = Me.EmailAddress
.CC = "patrick.keaveney@hobtpct.nhs.uk"
.Subject = mess_subject
.Body = mess_body
.Send​

End With


SendEMailOK = True

Exit_SendEMail:
Exit Sub

Err_SendEMail:

MsgBox " Error" & Err.Description & Err.Number
Resume Exit_SendEMail:


End Sub
 
Last edited:

Paul Buttress

Registered User.
Local time
Today, 20:39
Joined
Feb 4, 2008
Messages
25
Pat

I generate email via an Access database but I use jmail. It's so much easier and quicker to generate.

I'm sorry that I don't have much time today but tomorrow I will send you some sample code. In the mean time check out jmail.

I promise - it will be worth it in the long run.

Paul
 

patkeaveney

Registered User.
Local time
Today, 20:39
Joined
Oct 12, 2005
Messages
75
Thanks

Thanks all

My problem was that I did not have a reference to microsoft outlook libary in my code
 

Users who are viewing this thread

Top Bottom