Error trapping

Steven811

Registered User.
Local time
Today, 10:59
Joined
Apr 18, 2004
Messages
133
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:

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

Works a treat, thanks.
 

Users who are viewing this thread

Back
Top Bottom