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
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 = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
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 "mailto" 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 "On doubleclick" event for an email field I have (field in this example is called "Email":
_________________________________________________
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.