Back to Samples Menu

VBA Samples

Microsoft Access

Email on Double-Click

We wanted to be able to double-click an email address in a form and have it open an automatically addressed email message. We formatted the field as a hyperlink and thought this was enough. By default, however, Access thinks all hyperlinks are web pages and when you click, it opens your browser and tells you that the page is not found.

This one was submitted by Buck Hicks.

We needed to format the field as text instead of as hyperlink, and create a double-click event procedure. Next time you want to do that, just choose the Event properties tab in the properties of your field, choose Event procedure for the On Double-Click. Hit the builder (the . . . that follows the property). This opens the VB Editor window. You can directly paste the following code at this point. Now, change EmailAddressFieldName to your field's name. Hit the *save* diskette icon in the VB Editor window and close the window. Save your form and test! Thank you, Buck!

On Error GoTo errhandler

Dim strEmail As String

If IsNull(Me.EmailAddressFieldName) Then
MsgBox ("There is no email address shown")
Exit Sub
ElseIf Me.EmailAddressFieldName = " " Then
MsgBox ("There is no email address shown")
Exit Sub
End If
strEmail = Me.EmailAddressFieldName
DoCmd.SendObject , , , strEmail, , , , , True

errhandler:
Exit Sub