Email Code

C

CAM

Hello,

I am trying to figure out what is wrong with my code (see below). When I
press the email button I get two New message from outlook. The first show
the actual email message and then a second new message appearing, but is
blank. What am I doing wrong. I should only get the e-mail with message
displaying not a blank. Thank you in advance.

Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

'email notification response
Dim email As String
Dim ref As String
Dim EmailNotification As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
email = GroupMemberEmail
EmailNotification = Notification
ref = "Update Master Project Database"
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
..To = email
..Subject = ref
..body = EmailNotification
..Display
End With

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub
 
G

Guest

This is code I use in my database. Just modify the fields to your needs.
Shouldn't have any problems, works very well for me.

Private Sub Command51_Click()
On Error GoTo eh
Dim SendTo As String, MySubject As String, MyMessage As String
SendTo = "whatever email (e-mail address removed)"
MySubject = "TEST"
MyMessage = TEST

DoCmd.SendObject acSendNoObject, , , SendTo, , , MySubject, MyMessage, True

eh:
If Err.Number = 2501 Then
MsgBox "This email message has not been sent. Message has been
cancelled."
End If
End Sub
 
C

CAM

Thanks for your help.
Regards,

Doug_C said:
This is code I use in my database. Just modify the fields to your needs.
Shouldn't have any problems, works very well for me.

Private Sub Command51_Click()
On Error GoTo eh
Dim SendTo As String, MySubject As String, MyMessage As String
SendTo = "whatever email (e-mail address removed)"
MySubject = "TEST"
MyMessage = TEST

DoCmd.SendObject acSendNoObject, , , SendTo, , , MySubject, MyMessage,
True

eh:
If Err.Number = 2501 Then
MsgBox "This email message has not been sent. Message has been
cancelled."
End If
End Sub
 

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