DoCmd.SendObject alternative (1 Viewer)

sambucaman

Registered User.
Local time
Yesterday, 16:22
Joined
May 6, 2010
Messages
41
Hi all. I'm new to access, so apologies if this is a daft question. I have tried searching forums and Google, but cant seem to get an answer. Using access 2003.

I have a fairly basic database; name, address, email address - that sort of thing.

I have masted mail merge, queries, address labels, etc, and the last thing I need to fix is email.

I would like to be able to search for a customer by name using
Like "*" & [search by name] & "*"

The results are displayed in a form, which has a "Print Label" button, and "call history" ect. Id like an "email" button, which will open a new email in outlook, with the customers email address already in the address bar. I dont want to auto send, or use default text, just open a blank email.

I have tried DoCmd.SendObject, as follows
DoCmd.SendObject _
, _
, _
, _
"Email Address", _
, _
, _
"Subject", _
"Message", _
False

I have a feeling I am WAYYYY off track, lol.

FYI, table and form is called "Contacts" email field is called "Email Address"
Any sugegstions?
Thanks in advance, Andy
 

Kiwiman

Registered User
Local time
Today, 00:22
Joined
Apr 27, 2008
Messages
799
Howzit

Something like this will work - you will need to have referenced in the Outlook library.

Code:
Private Sub cmdEmail_Click()

Dim sTo As String
Dim sCC As String
Dim sBCC As String
Dim sSub As String
Dim sBody As String
Dim strCC As String
Dim OutApp As Object
Dim OutMail As Object
Dim varPress As Variant

' Original code copied from http://www.ozgrid.com/forum/showthread.php?t=51384

strMess = "You are about to send an email message to the current user." & vbCrLf & vbCrLf
strMess = strMess & "Do you wish to continue?"

strStyle = vbYesNo
strTitle = "Send Notificaiton"

varPress = MsgBox(strMess, strStyle, strTitle)
If varPress = vbYes Then
    ' Get the email address from the current form control
    sTo = Me.EmailAddress
    
    '  Set the subject 
    sSub = "Some subject matter"

    ' Build the body of the email
    sBody = Me.FirstName & vbCrLf & vbCrLf
    sBody = sBody & "Continue with message
    
    ' Create the email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    sCC = ""
    sBCC = ""
    
  
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSub
        .Body = sBody
        .Display          ' THis will display the email, but not send it
        '.Send            ' THis will send the email
    End With
    Set OutMail = Nothing
    Set OutApp = Nothing
End If


End Sub
 

sambucaman

Registered User.
Local time
Yesterday, 16:22
Joined
May 6, 2010
Messages
41
Thanks Kiwiman, pretty much 100% what i needed.

:)
 

Users who are viewing this thread

Top Bottom