473,388 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to make Access to send an e-mail using Outlook...

41 32bit
Dear all...

I was wondering if you could please help me to understand how to make access to send an e-mail using outlook.
I also would like to leave such message in outlook's "messages sent" folder.

Is it possible?

At this moment, since I'm starting the tests, I just want to create a button in a form that sends a message when pressed.

Best Regards
Ricardo de Milano
Jul 17 '15 #1

✓ answered by zmbd

Ricardo,
Please use the search feature of this site, this has been covered many many times.

If you want to send simple emails then the SendObject command is my go to method.
DoCmd.SendObject Method (Access)

For anything more complex then automation is the route:
Application Automation
(the first link also has a workable example)

4 1372
zmbd
5,501 Expert Mod 4TB
Ricardo,
Please use the search feature of this site, this has been covered many many times.

If you want to send simple emails then the SendObject command is my go to method.
DoCmd.SendObject Method (Access)

For anything more complex then automation is the route:
Application Automation
(the first link also has a workable example)
Jul 17 '15 #2
Ricardo de Mila
41 32bit
Dear zmbd...

Thank you very, very much for your reply.
Sorry for asking about a subject that was there already. I'm not very familiar with the system and tryed to find some previous information, but could not. I will apply some more effort in the future.

About the answer received, I still could not test and check everything, but apparently it solves all my initial questions.
Very nice answer.

Thank you very, very much again.

Best Regards
Ricardo de Milano
Jul 18 '15 #3
Ricardo de Mila
41 32bit
I have tested the proposed solution and unfortunately I'm doing something wrong.

While trying to create the new email object, with the line "Set olMailItem = olApp.CreateItem(olMailItem)", I'm receiveing the following error message:

Error 91
The object variable or the variable of the 'with' block was not defined.

I could not handle the error.

The procedures I have used are subscribed, but any way, with your help I think I could jump to the next step with the instruction DoCmd.SendObject.
If you can continue help me with the issue I'm facing would be very glad, but any way, I think I can handle from here.

Thank you very very much.

Expand|Select|Wrap|Line Numbers
  1. Public Function SendEmailWithOutlook(MessageTo As String, Subject As String, MessageBody As String)
  2.  
  3.     ' Define app variable and get Outlook using the "New" keyword
  4.     Dim olApp As New Outlook.Application
  5.     Dim olMailItem As Outlook.MailItem  ' An Outlook Mail item
  6.  
  7.     ' Create a new email object
  8.     Set olMailItem = olApp.CreateItem(olMailItem)
  9.  
  10. Debug.Print MessageTo, Subject, MessageBody
  11.  
  12.     ' Add the To/Subject/Body to the message and display the message
  13.     With olMailItem
  14.         .To = MessageTo
  15.         .Subject = Subject
  16.         .Body = MessageBody
  17.         .Send       ' Send the message immediately
  18.     End With
  19.  
  20.     ' Release all object variables
  21.     Set olMailItem = Nothing
  22.     Set olApp = Nothing
  23.  
  24. End Function
  25. Private Sub Comando161_Click()
  26. Dim Vx As Variant
  27.  
  28. On Error GoTo Err_Comando161_Click
  29.  
  30. Vx = SendEmailWithOutlook("Ricardo.Milano@GrupoAutcomp.com.br", "Impossível cotar", "Test")
  31.  
  32. 'DoCmd.SendObject acSendNoObject, , , "Ricardo.Milano@GrupoAutcomp.com.br", , , "Impossível cotar", "Just a test"
  33.  
  34. Exit_Comando161_Click:
  35.     Exit Sub
  36.  
  37. Err_Comando161_Click:
  38.     Call ErrMsg("Private Sub Comando161_Click()", Me.Name)
  39.     Resume Exit_Comando161_Click
  40.  
  41. End Sub
Jul 20 '15 #4
zmbd
5,501 Expert Mod 4TB
Sorry to be so late returning to this thread. Been series of upsets in my personal life and at work :(

This error tells me that you missed "step 1" in the automation article. The reference to the Outlook application must be set first (early binding) to use this approach.

There is a method to (late binding) where the reference is "set" during the run; however, it appears that you might be more comfortable using the early binding approach.

Open your VBA editor (Alt-F11)
Then in the menu>Tools>References
Scroll thru the list for an entry referring to the Outlook version you have installed (for Office 2013 = Microsoft Outlook 15.0 Object Library)
Checkmark-select this entry and then OK.

Debug>Compile

Fix any errors that pop-up

-z
Oct 4 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Nick Li | last post by:
Hi, I am trying to writing a c program to send email using system() function call on Unix(Sun Solaris). I tried the following: #include <stdio.h> #include <stdio.h> int main(void) {
1
by: perryche | last post by:
I have coded MS Access 2002 to send a report via email using outlook. However, if outlook is already run, it will just sit there. I have checked Send every 1 min when outlook is offline, but it...
11
by: Mohammed Abdel-Razzak | last post by:
dear sirs i want to send email using c# but i don`t want to use CDONTS or tell me how can i use it i don`t know any thing about CDONTS thanks
4
by: roni | last post by:
i dont like to use ocx controlx. is there new dll for vb.net that do the job ? or newer code, to send email throught outlook express.
2
by: Senthilkumar | last post by:
Hi, I would like to send mail using Outlook or Outlook Express my .net program which is written using vb.net . When ever a new record of particular type is added, i would like to send an...
0
by: Tidan | last post by:
Hi, I would like to send mail using Outlook Express my .net program which is written using vb.net 2.0. When ever a new record of particular type is added, i would like to send an automatic mail...
0
by: thinkwebs | last post by:
hi guys Just i am trying to send email using syste.web.mail in ASP.Net just i have send mail successfully in the web but i can't send mail with attachment in the web. But my coding works properly...
0
by: Bibin | last post by:
I want to send email via Outlook Express and not by Outlook in VB.NET (windows application). I also want to attach files with the email. The mail (in Outlook Express) needs to be displayed before...
10
by: Corwin Moyne | last post by:
Hi there. I'm a complete noob when it comes to VBA. I have some code that I got online to send an email using Outlook through Access 2010. The code works by displaying an Outlook message window, but...
5
by: slburke67 | last post by:
I have a couple of forms that track the status of our orders. In both forms I would like to update a date field in a table as the data the checkbox was checked as well as send an email to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.