Using MS Access/MS Access & Email

Advertisement


Question
Is it possible to Click on a Button,(ON Open)  that then opens up MS Mail application and sends a prepared message to a person named in a field called email..

Answer
Hi David,

Thanks for the question.

The short answer is Yes, you can click on a button, to open a previously prepared email message.

To do this:

When you add the button, click the cancel button.

Then open the Property Sheet > Event Tab > Place your cursor nest to On Click, and click on the button with the 3 dots '...'


Choose code builder and okay.

The similar code to the following two lines will appear:

Private Sub Command586_Click()

End Sub

In between these two lines of code add the following code:



   Dim objOutlook As Object 'Outlook.Application
   Dim objMailItem As Object 'Outlook.MailItem
   Dim EmailAddress As String

   
   

   Set objOutlook = CreateObject("Outlook.Application")
   Set objMailItem = objOutlook.CreateItem(0)
   
       DoCmd.RunCommand acCmdSaveRecord
       EmailAddress = Me!Email  'Put the email address here, this one looks it up from the form
       With objMailItem
         
         .To = EmailAddress
         .Subject = "Add your subject title here"
         .body = "Add the content of your body here" & vbCrLf & vbCrLf & "Use VbCrLf for new lines" & vbCrLf
         .Display
       End With

Close the VBA window by clicking on the upper outer right hand X.

Run and test your code


Hope this is what you are looking for  

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Julie Misson

Expertise

My area of expertise is Microsoft Access 2000-2007. I have been building microsoft databases for the past twelve years. I would be competent in answering questions from novice Access 2000 users to the more advanced including VBA. If I cannot help, I am more than likely be able to point you to websites that can.

Experience

I have a Microsoft Access business where I build database for small businesses. These are usually one off designs, where there is no off the shelf software avaliable to meet the business needs. I also teach Microsft Access to beginners. I am the owner of the www.simply-access.com website.

Education/Credentials
Self taught in Microsoft Access. Have done some units in normalisation and SQL, but most of what I know I have learnt from books originally and more recently the Internet.

©2016 About.com. All rights reserved.