![]() |
PROJECT PERFECT Project Management Software Specialists in Project Infrastructure |
z
|
|
Home - Microsoft Access Development - Microsoft Access Tips Sending Emails and Storing HyperlinksSend an Outlook Email from Access, create a file, then store
|
|---|
| Button in Access | Makes sure Outlook is open. Creates a new Email. in Outlook |
MessageSave in Outlook |
When the Email. is sent, MessageSave prompts to save the Email. and handles selection of a location and file name. When saved it calls a VBScript to execute. |
VBScript creates temporary text file |
The VBScript writes the saved Email. file name into a one line temporary text file. |
| Access reads the temporary file | After the Email. is sent, control returns to Access. It reads the temporary file and writes the file name to the DocLink field in tblDocuments. It also does some housekeeping such as deleting the temporary file. |
![]()
There is a form that collects To, Subject and Body. You can use it or not. I included it to show how it could be used to transfer information to Outlook but you could just have a button on a form that opened a blank Email.
The first part is the establishment of the name and path of the temporary file. It is called temp.txt and is in the same location as the database. I use a generic routine funGetDBPath to find the current path.
Option Compare Database '++++++++++ Start of Declarations ++++++++++++++++++++++++++++++ '++++++++++ Start of Opening Actions ++++++++++++++++++++++++++++ strFileName = funGetDBPath & "\temp.txt" ' Name of the temp file inc. path Error_Form_Open: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ '--------------------------------------------------------------------------------------- On Error GoTo Error_funGetDBPath strFullPath = CurrentDb().Name '-------------------------------------------------------------- Exit_funGetDBPath: Error_funGetDBPath: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ |
The next section sends the email and writes to the table. There are a number of subroutines.
One part that may need explanation is the creation of the hyperlink. An Access hyperlink is in two parts at least, separated by a #. The first part is what is displayed and the second the path to the file. I have just used the same for both parts.
'--------------------------------------------------------------- '--------------------------------------------------------------- Exit_btnSendEmail_Click: Error_btnSendEmail_Click: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ End Sub '--------------------------------------------------------------------------------------- On Error GoTo Error_subSendEmail '--------------------------------------------------------------- '--------------------------------------------------------------- Exit_subSendEmail: Error_subSendEmail: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ End Sub '--------------------------------------------------------------------------------------- '--------------------------------------------------------------- Exit_subWriteDocDetails: Error_subWriteDocDetails: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ '--------------------------------------------------------------------------------------- On Error GoTo Error_subWait Call MsgBox("Click to return.", vbInformation, "Email Sent") Exit_subWait: Error_subWait: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ End Sub '--------------------------------------------------------------------------------------- intTest = GetAttr(strPath) Exit_funFileExists: End Function '--------------------------------------------------------------------------------------- On Error GoTo Error_subRunUpdateQuery Exit_subRunUpdateQuery: Error_subRunUpdateQuery: MsgBox "An unexpected situation arose in your program." & vbCrLf & _ |
![]()
There are a number of enhancements you can make. For example you can save other information to the document table, or pass a form field into the internet. This is the basic function to get you started.
![]()
If you want to store received emails we have a similar function in the sample database to open Outlook. Use MessageSave to save the email from your Inbox, then Access will store the details.
![]()
The key thing in the configuration is to set the After Saving Messages, Execute field to point to the VBScript file in the download. This creates the temporary text file.

The othe piece of critical configuration is to select the Prompt to save sent messages.

To download the database (Access 2007), Click Here
![]()
![]()