Home  Fees/Services  Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access VBA Tutorial
   
Access Programming Examples
Create Outlook Email Using Access Form

Send Email From Access Form Visual Basic Tutorials for Access 2007 VBA
Access 2007 Tutorial>Visual Basic Tutorial>Launch Outlook Download VBA Tutorials  



Age Calculation
VBA Change Case
Calculate Running Sum
Concatenate Records
VBA CreateQueryDef
Database Path
Detail-Master Update
Field Validation VBA
Field Value New-Old
FindFirst Recordset
Get Version Number
VBA Global Parameters
VBA Global Variables
Labels as Links
VBA Outlook Email
List Box Files List
VBA Mail Merge
OutputTo Crosstab
Read Email Access
Sort Recordset
VBA Recordset Filters
Reference Form Field
RTF Report Email
VBA Select Case
VBA Transaction Processing

Visual Basic Function Examples


Launch Outlook Email from Access Form


To enhance a contact form that contains the individual’s e-mail address you can add a button to automatically launch outlook using that address.

Run MS Outlook Access Form

The first step is to locate the e-mail client, outlook.exe, on the system that uses the application. For example on the Windows XP Professional operating system using Office XP with a standard installation the outlook client can be found in C:\Program Files\Microsoft Office\Office10. You can simply hard code the location of the e-mail client directly into your code but I prefer to store it in a table, giving the user a simple interface to the table where they can enter the location themselves if necessary.

We have three examples showing how you can make your Access database interact with Outlook Email functions:

The concept behind this is to use outlook command line options to launch an e-mail message with the address from the form.

New! Download Access example of  Sending Email to Outlook

Simply add a button to the form and in the OnClick event add the following code. Note that the e-mail address is in a control named ContactEmail in this example.

Private Sub btnEmail_Click()
Dim EmailClient As Variant
Dim stAppName As String
Dim ClientName As String

On Error GoTo Err_btnEmail_Click

‘ Look up the base directory of the e-mail client in table EmailClient
EmailClient = Trim(DLookup("OutLookAddress", "EmailClient"))
If IsNull(EmailClient) Then
    ' Open a simple form asking the user to enter the base directory
    DoCmd.OpenForm "EmailClient", , , , acFormAdd
Else
    If Not IsNull(Me!ContactEmail) And Not IsNull(EmailClient) Then
        ' if there is a \ on the end remove it
        If InStr(Len(EmailClient), EmailClient, "\") Then
            EmailClient = Left(EmailClient, Len(EmailClient) - 1)
        End If
        ‘ add the outlook client, set the command line options, add the form address
        stAppName = EmailClient & "\outlook.exe /c ipm.note /m " & Me!ContactEmail
        ‘ Launch Outlook
        Call Shell(stAppName, 1)
    Else
        MsgBox "The Email Client or Email Address is Null, please enter it"
    End If
End If
Exit_btnEmail_Click:
Exit Sub

Err_btnEmail_Click:
MsgBox Err.Description
Resume Exit_btnEmail_Click

End Sub

The important command line information is on the line

stAppName = EmailClient & "\outlook.exe /c ipm.note /m " & Me!ContactEmail

• /c indicates create an object
• ipm.note specifies that you want an e-mail message
• /m says use the following e-mail address in To:
• Me!ContactEmail pulls the e-mail address from the form

Contributed by Janet Loch




Contact Information

Programming Visual Basic Tutorial

Access Visual Basic/VBA/VBScript/VB6 2007 2003 2000