Thank you for your help. Here is my code but it keeps getting stuck on
(rsRecip.UserID("EMail")) part of the code specfically the userID which is
the field that contains the email address in the query. Can anyone help.
Sub SendMessage()
Dim qdf As DAO.QueryDefs
Dim rsRecip As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim clsSendObject As accSendObject
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Open the recordset so you can loop through it.
Set rsRecip = DBEngine(0)(0).QueryDefs("Current Case Query Within
15 Days")
Do Until rsRecip.EOF
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(rsRecip.UserID("EMail"))
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft"
Outlook ""
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
George Nicholson said:
1) Per the DAO Help file, Database.OpenQueryDef is an obsolete method. Use
the Querydefs collection instead.
2) If the OP is using Access 2007 and working in an Access 2007 format file,
they will not have a separate DAO reference listed. The "Access 12 Object
Library" includes DAO.
HTH,