Run-time error 462 shows every other round

S

Song Su

Access 2007 SP2 on XP

When I click email button on the continues form, first time ok. 2nd time
shows runtime error 462 - the remote server machine does not exist or is
unavailable. It highlights Set objMail=olApp.CreateItem(olMailItem) Please
help. Thank you.

Private Sub cmdEmail_Click()
If IsNull(Me.Email) Or Len(Me.Email) < 8 Then
MsgBox "No email address.", , conAppName
Else
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim ctlBody As String

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

ctlBody = "Dear " & IIf([Sex] = "M", "Mr. ", "Ms. ") & StrConv([First],
3) & " " & IIf(IsNull([M]), "", [M] & ". ") & StrConv([Last], 3) & ",<p>"

With objMail
.To = Me.Email
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>" & ctlBody & "</p></BODY></HTML>"
.Display
End With

Set objMail = Nothing
Set olApp = Nothing
End If

End Sub
 
S

Song Su

I fixed it following the suggestion on the item below my post -
CreateObject("Outlook.Application")
 
D

Douglas J. Steele

Your other option would have been to change

Set olApp = Outlook.Application

to

Set olApp = New Outlook.Application

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Song Su said:
I fixed it following the suggestion on the item below my post -
CreateObject("Outlook.Application")

Song Su said:
Access 2007 SP2 on XP

When I click email button on the continues form, first time ok. 2nd time
shows runtime error 462 - the remote server machine does not exist or is
unavailable. It highlights Set objMail=olApp.CreateItem(olMailItem)
Please help. Thank you.

Private Sub cmdEmail_Click()
If IsNull(Me.Email) Or Len(Me.Email) < 8 Then
MsgBox "No email address.", , conAppName
Else
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim ctlBody As String

Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

ctlBody = "Dear " & IIf([Sex] = "M", "Mr. ", "Ms. ") & StrConv([First],
3) & " " & IIf(IsNull([M]), "", [M] & ". ") & StrConv([Last], 3) & ",<p>"

With objMail
.To = Me.Email
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>" & ctlBody & "</p></BODY></HTML>"
.Display
End With

Set objMail = Nothing
Set olApp = Nothing
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top