Test for required fields, and exit if any are empty:
strSubject = Me![txtSubject].Value
If strSubject = “” Then
MsgBox “Please enter a subject”
Me![txtSubject].SetFocus
GoTo ErrorHandlerExit
End If
strBody = Me![txtBody].Value
If strBody = “” Then
MsgBox “Please enter a message body”
Me![txtBody].SetFocus
GoTo ErrorHandlerExit
End If
For Each varItem In lst.ItemsSelected
Check for email address:
strEMailRecipient = Nz(lst.Column(1, varItem))
Debug.Print “EMail address: “ & strEMailRecipient
If strEMailRecipient = “” Then
GoTo NextContact
End If
Create new mail message and send to the current contact:
Set appOutlook = GetObject(, “Outlook.Application”)
Set msg = appOutlook.CreateItem(olMailItem)
With msg
.To = strEMailRecipient
.Subject = strSubject
.Body = strBody
.Display
End With
NextContact:
Next varItem
ErrorHandlerExit:
Set appOutlook = Nothing
Exit Sub
ErrorHandler:
Outlook is not running; open Outlook with CreateObject:
If Err.Number = 429 Then
Set appOutlook = CreateObject(“Outlook.Application”)
Organizing and Communicating with Outlook 4