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 SkipVought 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 send emails in Outlook from hyperlinks

Status
Not open for further replies.

VicBlake

Technical User
Jan 29, 2002
19
0
0
GB
I want to be able to send an e-mail by clicking on an hyperlink in Access. Any suggestions?
 
On your form just add a hyperlink and in the hyperlink dialogue box select e-mail. Randusoleis.....
 
Create a command button next to the email field and place the following code. Please note I did not write the code, however it then puts the email address in outlook in the
to box.

Note contactemail is the field which contains the email address,

Private Sub cmdEmail_Click()
Dim x
x = fHandleFile("mailto:" & Me!ContactEMail, WIN_NORMAL)
End Sub

In a module place the following code

Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 2 'Open Maximized
Public Const WIN_MIN = 3 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&


Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = &quot;Error: Out of Memory/Resources. Couldn't Execute!&quot;
Case ERROR_FILE_NOT_FOUND:
stRet = &quot;Error: File not found. Couldn't Execute!&quot;
Case ERROR_PATH_NOT_FOUND:
stRet = &quot;Error: Path not found. Couldn't Execute!&quot;
Case ERROR_BAD_FORMAT:
stRet = &quot;Error: Bad File Format. Couldn't Execute!&quot;
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = &quot;&quot;, vbNullString, &quot;, &quot; & stRet)
End Function


Regards




Jason
 
The GUI method is a lot easier if you have a static e-mail address. Will the users be sending an e-mail to the same address all the time? Randusoleis.....
 
This is really close to what I'm trying to do as well, is there a way to add an attachment to the &quot;mailto&quot; part of the script? essentially tack on the sendObject script?
 
The way I handle this (hopefully to inspire you for what you want to achieve):

I have some fields on some forms with an email adress in it.
In order to launch sending an email to that adress via the default Outlook, I require a doubleclick on the field (a single click too often causes inadvertant action).
The fields in question are defined as ordinary data type text.

For the &quot;On doubleclick&quot; event for an email field I have (field in this example is called &quot;Email&quot;):

_________________________________________________
Private Sub Email_DblClick(Cancel As Integer)

fMyEmail

End Sub
_________________________________________________
Function fMyEmail() As Boolean

Dim CurrentControl As Control
Set CurrentControl = Screen.ActiveControl
On Error Resume Next

DoCmd.SendObject acSendNoObject, , acFormatRTF, CurrentControl, , , , , -1

End Function
_________________________________________________


So for every other field with an email adress in it, just put
fMyEmail
as &quot;on doubleclick&quot; event

Hth :)
Riny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top