paste this SUB into the form's module, and call it from your button click
event.
you'll need to do a DLOOKUP or create a recordset to get the customer info
from the database first...
basically the code fires up an outlook mail item and fills in the email then
sits there and waits for you to send it / edit it from outlook.
if you just want to send it transparently, then use the .send instead of
the .Display......
see how it works then refine the variablers for your own use.
Private Sub SendMail_Click()
#If 6 = 7 Then
'declarations like this require a reference to the Outlook Type Library
'this can be a nuisance for installation and compilation
'therefore just declare the variables as objects and trap the run time
errors
'if Outlook is not installed
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
#End If
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
If IsNull(Me.EmailAddress) Then
If MsgBox("There is no Email Recipient specified in the [Email To:]
box." & vbCrLf _
& "Do you wish to create the Email anyway?", vbQuestion _
+ vbYesNo, "No Recipient(s) Specified") = vbNo Then Exit Sub
End If
On Error Resume Next
'Create the Outlook session.
Set objOutlook = GetObject(, "Outlook.Application") 'get reference
if Outlook is already running.
If Err.Number = 429 Then 'Error 429
occurs if Outlook is NOT running.
Err.Number = 0
Set objOutlook = CreateObject("Outlook.Application") 'Create a new
instance of the Outlook application.
If Err.Number = 429 Then 'Error 429 will
occur if MS Outlook is not installed.
MsgBox "MS Outlook is not installed on your computer"
Exit Sub
End If
End If
On Error GoTo Err_SendMail_Click
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
With objOutlookMsg
' Add the To recipient(s) to the message.
If Not IsNull(Me.EmailAddress) Then
Set objOutlookRecip = .Recipients.Add(Me.EmailAddress)
objOutlookRecip.Type = 1 'olTo
End If
' Set the Subject and Body of the message.
.Subject = Me.Jobs_Description
.Body = "Re:- " & vbCrLf & "Our Job Code:- " & Me.JobCode _
& vbCrLf & "Our Job Name:- " & Me.Jobs_Description & vbCrLf &
vbCrLf
If Not IsNull(Me.DirectoryName) Then
Set objOutlookAttach = .Attachments.Add(Me.DirectoryName & "\" &
Me.FileName)
Else
'there is no attachment
' Set the Subject and Body of the message.
.Subject = Me.DocumentsOut_Description
.Body = vbCrLf & Details
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' display message
.Display
'.send ' if you want to send it automatically
End With
Set objOutlook = Nothing
Exit_SendMail_Click:
Exit Sub
Err_SendMail_Click:
MsgBox Err.Description, vbInformation, "Email Error"
Resume Exit_SendMail_Click
Resume
End Sub