Linking Email field to Outlook "new" mail

J

jlm

Is there a way to have a field for email that when I click on the email
address, Outlook opens with that email address in the "to" field? (or if I
have Outlook already open, that clicking on the email address pops Outlook up
with that email address in the "to" field). Making the email address field a
hyperlink doesn't do this, it causes the program to pop up a browser.
 
T

Tom Wickerath

Hi Jim,

Try something like the following. I'd probably use the double-click event
procedure, just to avoid accidentally opening up a new mail message by
clicking (or use a command button instead). This is for a textbox named
"txtEMail":

Option Compare Database
Option Explicit

Private Sub txtEMail_DblClick(Cancel As Integer)
On Error GoTo ProcError

Application.FollowHyperlink "mailto:" & Me.EMailColumnName

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtEMail_DblClick..."
Resume ExitProc
End Sub


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
T

Tom Wickerath

PS. My original example was written for a textbox named "txtEmail", which is
bound to a field named "EMailColumnName". Sorry that I was not clear on that.
Also, you may want to save the record first, just in case the e-mail address
is edited but the record is not committed, when the user double-clicks on the
textbox. Here is an alternate procedure which does not reference the field
name, and it ensures that a change will be saved first:

Option Compare Database
Option Explicit

Private Sub txtEMail_DblClick(Cancel As Integer)
On Error GoTo ProcError

'Save the record first
If Me.Dirty = True Then
Me.Dirty = False
End If

Application.FollowHyperlink "mailto:" & Me.txtEMail

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtEMail_DblClick..."
Resume ExitProc
End Sub


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
J

jlm

thank you so much!

Tom Wickerath said:
PS. My original example was written for a textbox named "txtEmail", which is
bound to a field named "EMailColumnName". Sorry that I was not clear on that.
Also, you may want to save the record first, just in case the e-mail address
is edited but the record is not committed, when the user double-clicks on the
textbox. Here is an alternate procedure which does not reference the field
name, and it ensures that a change will be saved first:

Option Compare Database
Option Explicit

Private Sub txtEMail_DblClick(Cancel As Integer)
On Error GoTo ProcError

'Save the record first
If Me.Dirty = True Then
Me.Dirty = False
End If

Application.FollowHyperlink "mailto:" & Me.txtEMail

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure txtEMail_DblClick..."
Resume ExitProc
End Sub


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
M

missvalerina

Hi, I am having the same issue, but I cannot get this code to work. Is there
something I should be doing differently? I copied the code exactly except for
where txt.EMail was I replaced it with Email, which is what my textbox was
named. Thanks.
 
T

Tom Wickerath

"but I cannot get this code to work."

This doesn't give me any information that I can use to try to help you get
this working. Have you tried it on a different PC, just to rule out some type
of configuration problem on your PC? Try adding a break point on the first
line of code:
On Error GoTo ProcError

When you double-click your textbox control, does the VBA editor open up at
this line of code in suspended mode? If so, use the F8 key to single step
through the code. What happens?


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
M

missvalerina

I'm sorry, I'm not very familiar with Access so everything in these threads
sounds like Chinese to me!
 
M

missvalerina

I'm sorry, I'm not very familiar with Access so most of the stuff in these
topics sounds like Chinese to me!
 
T

Tom Wickerath

If you are willing to send me a compacted (Tools > Database Utilities >
Compact and repair database) and zipped copy of your database, I will take a
look at it. You can sanitize the data, if necessary, although leave some test
data so that I can try it out without having to spend time entering test data.

If you are interested, my e-mail address is available at the bottom of the
contributor's page indicated below. Whatever you do, please do not post your
e-mail address (or mine) to a newsgroup reply.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
M

missvalerina

I figured it out. Thanks for your help!

Tom Wickerath said:
If you are willing to send me a compacted (Tools > Database Utilities >
Compact and repair database) and zipped copy of your database, I will take a
look at it. You can sanitize the data, if necessary, although leave some test
data so that I can try it out without having to spend time entering test data.

If you are interested, my e-mail address is available at the bottom of the
contributor's page indicated below. Whatever you do, please do not post your
e-mail address (or mine) to a newsgroup reply.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
B

BillD

This Event Procedure on Dbl Click in my EMail text box worked fantastic. I
have been looking for a way to start Outlook in an Access2000 database and
have the EMail address put into the EMail Address Field automatically.
Before this I was copying the EMail Address from the Access Form and pasting
it to The Outlook EMail line.
Thank you sooooo much. This will save me a lot of work and avoid errors when
sending email when I am in a members form.


Bill D
Fredericton, NB Canada
 
Top