Hmm. On doing a bit more research, it looks as though I was wrong, and the
line of code should work.
See whether changing
With .Recipients.Add(Me!txtTo)
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
to
Dim rcpMail As Outlook.Recipient
Set rcpMail = .Recipients.Add(Me!txtTo)
Set rcpMail.Type = olTo
If Not rcpMail.Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
works.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Hi
Thanks for taking the time to look at this.
It's always worked fine in previous versions of Access, but not in
2007 for some reason.
My code is as follows.
Private Sub NewMailMessage()
'Create a new mail message
Dim itmMail As Outlook.MailItem
On Error GoTo NewMailMessage_Error
'Return a reference to the MAPI layer
Set nsMAPI = olApp.GetNamespace("MAPI")
'Create a new mail message item
Set itmMail = olApp.CreateItem(olMailItem)
With itmMail
'Add the subject of the mail message
If Not NoData(Me!txtTo) Then
.Subject = Me!txtTo
Else
MsgBox "You must enter a recipient", vbOKOnly, "Outlook"
Me!txtTo.SetFocus
Exit Sub
End If
If Not NoData(Me!txtSubject) Then
.Subject = Me!txtSubject
Else
MsgBox "You must enter a subject", vbOKOnly, "Outlook"
Me!txtSubject.SetFocus
Exit Sub
End If
'
If Not NoData(Me!txtAdditionalMess) Then
.Body = Me!txtAdditionalMess
Else
End If
'Add a recipient and test to amke sure that the
'address is valid using the Resolve method
With .Recipients.Add(Me!txtTo)
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With
'Send the mail message
..Send
MsgBox "Your message was sent successfully", vbOKOnly, "Outlook"
End With
'Release memory
Set itmMail = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing
Exit Sub
NewMailMessage_Error:
Error_Handler ("NewMailMessage")
Exit Sub
End Sub