Sending Email



I am trying to send the current form as an attachment to the email. In the
process, I tried to send very simple emails but unfortunately was not
successful. I tried:

1) DoCmd.SendObject acSendNoObject, , , "myEmail", , , "some Subject ",

and then I also tried the following (which I got from a website)

2) Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

On Error GoTo ErrorMsgs

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute
' your names here.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
End If
End If
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
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. For
more information, see the document at
MsgBox Err.Number, Err.Description
End If

However, nothing happens when I click on the button. I have even made sure
that i have added references to Access Library, Outlook Library and Office

Note: I am using Access 2003.

Any idea?



Daniel Pineault

for 1.
if you look at the help you'll see that the proper synthax is like
expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc,
Subject, MessageText, EditMessage, TemplateFile)

Your code is
DoCmd.SendObject acSendNoObject, , , "myEmail", , , "some Subject ", "Hi"

You specify acSendNoObject when in fact you just said you want to send the
form so you should be using acSendForm.

Also, then you'll need to enter the form name as the second input variable.
Something like
DoCmd.SendObject acSendForm,"YourFormName" , , "myEmail", , , "some Subject
", "Hi"

for 2.
Does it not send out an e-mail? Do you receive any errors?

One thing I noticed is that you do not pull any data from the form for
inclusion within your e-mail.

You need to build the e-mail body content from your form controls.
Something like
.Body = "Hello," & vbcrlf & vbcrlf & "Here is the data:" & vbcrlf &
Me.ControlName1 & vbcrlf & Me.ControlName2
Hope this helps,

Daniel Pineault
For Access Tips and Examples:
Please rate this post using the vote buttons if it was helpful.

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