I have a field in a database on a form that holds the email address. I want to either double click or click a command button beside it to take me to an email window in outlook, something like the mailto: command in html can you suggest any ways I can do this.
Many thanks for the question.
I have recently done this for one of my databases. I chose to add the code to the 'On Double Click' event.
To do this:
Right click on your email field, and select 'Properties' from the drop down list. In the events Window, click on the 'Event' tab, and then place your cursor next to the 'On Double Click' then click on the '...' button. Select Code Builder, this will open the coding window with two lines of code. In between these two lines of code, add the following code:
On Error GoTo ErrorHandler
Dim objOutlook As Object 'Outlook.Application
Dim objMailItem As Object 'Outlook.MailItem
Dim EmailAddress As String
Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0)
EmailAddress = Me!Email
.To = EmailAddress
.Subject = "Enter Your Subject Here"
.body = "Enter the body of your email here if you wish Otherwise delete"
MsgBox "Error Number: " & err.Number & " " & err.Description
Hope this helps.
Note: I have used late binding, so that I do not have to reference Microsoft Outlook, otherwise you can run into strife if you try to load your database onto a computer that does not have the same version of Microsoft Outlook as the one you have referenced.
Also this code will only work if the email address is stored as text rather than the hyperlink option, as the hyperlink option adds some (invisible) text to the email address.
Do you like this tip? Subscribe to my free weekly Newsletter to receive tips weekly via email. Click Here to subscribe.