Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping

Status
Not open for further replies.

Steven811

Technical User
Apr 15, 2004
76
GB
Hi

I have a cmd button on a form to launch Outlook and populate the to: field with the email address from A2k, all works fine.

When the cmd button is selected and there is no data in the field an error message pops up [run-time error '94', invalid use of null]. I want to change the error message and instruct Access to ignore the cmd.

My code is as follows:

[Private Sub cmdEmail1_Click()
Dim Contact1emailaddress As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
email = Me!Contact1emailaddress
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = email

Response = acDataErrContinue

.Display
End With
Set objEmail = Nothing
Exit Sub
End Sub

How would I amend the code to do this

Thanks

Steven811
 
Look at the sample errorhandling added when using the wizards, there you can trap for a specific err.number, and display a custom message.

In this case however, in addition to some errorhandling, I'd use something like this:

[tt]if trim$(me!email & "")="" then
' your message
else
' your e-mailing code
end if[/tt]

Roy-Vidar
 
Private Sub cmdEmail1_Click()
Dim Contact1emailaddress As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
email = Me!Contact1emailaddress
If Trim(email & "") = "" Then
' your custom MsgBox here
Exit Sub
End If
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = email
.Display
End With
Set objEmail = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top