Problem with code which should send an Email

jayke

Registered User.
Local time
Today, 23:37
Joined
Nov 19, 2003
Messages
29
Hi,

I would like to send an Email via a button on my form.
I found a nice piece of code on this forum but.... when I try to compile the source it produces an error: "..... datatype is not defined"

This is de code I used:

Code:
Private Sub cmdSendEmail_Click()
On Error GoTo Error_Handler

    Dim objOutlook As Outlook.Application
    Dim objMsg As Outlook.MailItem
    Dim objRecipient As Outlook.Recipient
    Dim objMailAttachment As Outlook.Attachment
    

    Dim Attach1 As String
    Dim Attach2 As String
    Dim Attach3 As String
    Dim Attach4 As String
    Dim Rec As String
    Dim Subj As String
    Dim Main As String
        

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMsg = objOutlook.CreateItem(olMailItem)
    
    Attach1 = ""
    Attach2 = ""
    Attach3 = ""
    Attach4 = ""

    With objMsg
        .To = "r.cutts@tees.ac.uk"
        .Subject = "subject of e-mail"
        .Body = "body goes here"

        If Attach1 <> "" Then
            Set objMailAttachment = .Attachments.Add(Attach1)
        End If
        If Attach2 <> "" Then
            Set objMailAttachment = .Attachments.Add(Attach2)
        End If
        If Attach3 <> "" Then
            Set objMailAttachment = .Attachments.Add(Attach3)
        End If
        If Attach4 <> "" Then
            Set objMailAttachment = .Attachments.Add(Attach4)
        End If
            
        .send
    End With
     
    Set objOutlook = Nothing
    Set objMsg = Nothing
    Set objRecipient = Nothing
    Set objMailAttachment = Nothing

Error_Handler:
   If Err.Number = "287" Then
      MsgBox "You clicked No to the Outlook security warning. " & _
      "Rerun the procedure and click Yes to access e-mail" & _
      "addresses to send your message. "
   End If


'DoCmd.SetWarnings False
'DoCmd.SendObject , "", "", Form_VestigingenForm.txtEmail_ContactPersonen, "", "", "", "", False, ""
'DoCmd.SetWarnings True
End Function

Do I have to change some settings in my DB?

thx
 
Use Docmd.SendObject

Hi Jayke,

Search the help info for "DoCmd.SendObject". Here's a snippet of code. You will have to assign the values to the string variables (str...).

If IncludeNameAndAddress = True Then
DoCmd.SendObject acSendReport, "NameAndAddressReport", acFormatRTF, _
strTo, strCc, strBcc, strSubject, strYourEmailMessage, _
PreviewRequested 'Set to "True" if you want to preview the e-mail, else set to False.
Else
DoCmd.SendObject acSendNoObject, , acFormatRTF, _
strTo, strCc, strBcc, strSubject, strYourEmailMessage, _
PreviewRequested 'Set to "True" if you want to preview the e-mail, else set to False.
End If


Hope this helps,
DonK
 
Usually get that error when you are missing a reference.

Search the forums for "Missing Reference"
 

Users who are viewing this thread

Back
Top Bottom