| ||||||||||||
|
|
|
| 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
|
|