Run-time error 462 shows every other round

  • Thread starter Thread starter Song Su
  • Start date Start date
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
 
I fixed it following the suggestion on the item below my post -
CreateObject("Outlook.Application")
 
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
 
Back
Top