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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a hyperlinked field execute Outlook? 3

Status
Not open for further replies.

rlh777

Technical User
Oct 14, 2002
36
US
I've created a hyperlinked field for an e-mail address in my database. I would like to click this link and execute Outlook. So far I have been able to do this. However, I can not get the e-mail address to default in the mail to field. I don't want to designate one address only to default there, I would like whatever e-mail address I enter into the field to default into the Outlook mail form. Help!
 
I have a correction to make. This is the problem...I created an e-mail field in my database. I set the format of "Is Hyperlink" to "Yes". My problem is that when I enter an e-mail in the field it tries to send me to an http. I would like Outlook to execute on this field everytime it is clicked and I would like whatever e-mail address is in the field to defaul to the "Mail To" field.
 
rlh777,

one way to do this is to add the "mailto: " string right before your email address. simply use the update query to update old records, and use very simple VBA to add this string for all new entries. TestDrive
 
The subaddress of the hyperlink has to be set to an email address (mailto:).

I would just put a command button next to the hyperlink field on your form, and use code similar to the following to add or edit the hyperlink field:

Code:
' This is the button
Private Sub cmdHyperlink_Click()
  txtEmail.SetFocus
  Call GetHyperlink()
End Sub

' A function to launch the hyperlink editor
Sub GetHyperlink()
On Error GoTo ErrHandler
  DoCmd.RunCommand acCmdEditHyperlink
ExitHere:
  Exit Sub
ErrHandler:
  If Err <> 2501 Then ' If not canceled
    MsgBox &quot;Error occurred: &quot; & Err & &quot; - &quot; & Err.Description
    Resume ExitHere
  End If
End Sub

Place &quot;Add/Edit Hyperlink&quot; on the button's caption property.
VBSlammer
redinvader3walking.gif
 
Leave the field as text, not hyperlink.

Sub YourTextBox_Click()
DoCmd.SendObject , , , YourTextBox, , , , , True
End Sub

That will do

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
danvlas....

The string works and executes the e-mail, however, if I do not send the e-mail and close the e-mail form, I receive the following message. Run-time error '2501': The SendObject action was canceled. When I click debug, The DoCmd. string is highlighted. Any suggestions.
 
rlh777,

I'm not an expert here, but searching previous posts came up with the solution of using Application.FollowHyperlink method.

I created a common function &quot;OpenExplorer&quot; that receives a path and opens the file/directory/email using the default application. As the others suggested, an email address simply needs &quot;mailto:&quot; added to the start of the email address value (from your table) and sent to the public function.

---------------------------------------------------------
Public Function OpenExplorer(Path As String)
On Error GoTo ErrorHandler
Application.FollowHyperlink Path, , True

Exit_OpenExplorer:
Exit Function

ErrorHandler:
If Err.Number = 490 Then
MsgBox &quot;The file or folder doesn't Exist!&quot;, vbCritical, &quot;Folder Error!&quot;
Resume Exit_OpenExplorer
End If

MsgBox &quot;Error #: &quot; & Err.Number & vbCrLf & vbCrLf & Err.Description

End Function
--------------------------------------------------------

Works well, and you can cancel the email without any errors.
 
I'll add this for completeness...

To call the public function posted above, I use the following procedure:
-------------------------------------------------------
Private Sub EmailButton_Click()
If IsNull(EmailValue.Form!CaseEmail) = True Then
MsgBox &quot;No email address found.&quot;, vbInformation
Exit Sub
Else
OpenExplorer (&quot;mailto:&quot; & EmailValue.Form!CaseEmail)
End If
End Sub
-------------------------------------------------------
You'll notice how to add the &quot;mailto:&quot; string to the email address found on the form.
 
In response to the Canceled error, you'll find many situations where this message pops up.

Access uses error value 2501 to determine if a procedure was canceled, giving developers a way to respond if necessary. To handle the error, just add an error handler:
Code:
Sub YourTextBox_Click()
On Error GoTo ErrHandler

    DoCmd.SendObject , , , YourTextBox, , , , , True

ExitHere:
    Exit Sub
ErrHandler:
    If Err = 2501 Then
        ' do nothing
    Else
        MsgBox Err & &quot;-&quot; & Err.Description
    End IF
    Resume ExitHere
End Sub

VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top