473,398 Members | 2,393 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,398 software developers and data experts.

Access 2010 - VBA - How can I send email with Outlook? It just sits in outbox!

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 the message sits in the outbox until I open Outlook. Is there anyway to keep Outlook open long enough for the message to send. The reason I am asking is because this database will be used in work and I cannot guarantee that the guys will open Outlook to complete the message sending process.

Here is what I have so far. I have not added any content to the message yet as I am still testing:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Re_Order_Click()
  2.  
  3.         Dim OutApp As Object
  4.         Dim OutMail As Object
  5.         Dim blnOLOpen As Boolean
  6.  
  7.         On Error Resume Next
  8.         Set OutApp = GetObject(, "Outlook.Application")
  9.         blnOLOpen = True
  10.         If OutApp Is Nothing Then
  11.         Set OutApp = CreateObject("Outlook.Application")
  12.         blnOLOpen = False
  13.         End If
  14.         On Error GoTo 0
  15.  
  16.         Set OutMail = OutApp.CreateItem(olMailItem)
  17.  
  18.         With OutMail
  19.         .To = "email address"
  20.         .Subject = "This is the Subject line"
  21.         .Body = "testing"
  22.         .Display
  23.         '.Send - I have tried this without .display and                 does not work either
  24.         End With
  25. End Sub
Nov 18 '12 #1
10 13213
zmbd
5,501 Expert Mod 4TB
If you're sending only a single report, query etc... then the DoCmd.SendObject (type of obj), (name of obj), (format to send obj), (email to sendto), , , zsubject, zmessage, True would be the simplest [F1] to get the details.

Otherwise, you'll be wanting a more than a few changes to your code.
Nov 18 '12 #2
I don't need to send any objects. The body of the message will contain info on the fields from the originating form. I just need to keep Outlook open long enough for the message to send.
Nov 18 '12 #3
NeoPa
32,556 Expert Mod 16PB
OutApp needs to be maintained somewhere that won't die as soon as the procedure is finished. A Public variable in a persistent (Not object related) module would do the trick.

With Application Automation though, as with anything in code really, you should take resoponsibility for ensuring all objects used are closed tidily when finished with. This means ensuring Outlook is closed when it's finished with.
Nov 18 '12 #4
zmbd
5,501 Expert Mod 4TB
IF you will read thru the sendobject method you will find that you can just send a message:
http://msdn.microsoft.com/en-us/libr...ffice.14).aspx
I use this method in all of my production DB to send me an email if an error occurs... especially in beta testing!

The only issue I've found is when Outlook is not the default email client... but I.T. has solved that for the most part by force changing all of the PC to run Office... Gota luv a good I.T. staff (and I highly respect my local team!!!!)
Nov 18 '12 #5
fripau
2
I had the same problem today.
In the end, I had to go to Outlook Options > Advanced > Send and Receive and select Send immediately. That worked. With .send, it sends immediately without displaying and with .display it displays and when you then click on send it sends immediately.
May 30 '14 #6
I tried that a long time ago but it didn't work. I ended up bypassing outlook altogether and sending using gmail's SMTP server. Works great.
Jun 1 '14 #7
fripau
2
Thanks. Please point me in the right direction. How do you use gmail's SMTP server? I like gmail.
Jun 1 '14 #8
Hey. The following link shows how. Just replace the red writing with your own details.

http://www.blueclaw-db.com/access_email_gmail.htm
Jun 1 '14 #9
zmbd
5,501 Expert Mod 4TB
That link will take to a method using GMail.
You do not need to use GMail and instead one can usually have a go from within the PC, take a look at the code block here:
http://bytes.com/topic/access/answer...ok#post3742801

As Seth mentions in this post there are more complex versions.
You can also search this site for other examples of sending with CDO by using the search bar at the top of this page and the key words: Access, CDO, Email
Jun 11 '14 #10
twinnyfo
3,653 Expert Mod 2GB
Corwin,

Based on the code you used in your original post, I have found that based on your network's security settings, you may not be able to send e-mail directly from outlook with your methodolgy. I have used that same code before, and I would not get an error, but the e-mail would simply not send.

I have never, however, experienced a problem of the e-mail simply sitting in the outbox (this is the whole purpose of the ".Display"). My code would always generate the e-mail, and I can navigate throughout my db while the e-mail just sat open--it required me to click send, and that was it.

Did you ever find an acceptable solution to your original question?
Jun 11 '14 #11

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

Similar topics

3
by: Philippe Lang | last post by:
Hello, How can open a unix shell from a PLPGSQL function / trigger? I would like to send an email from a postgres database, and also send some unix commands to the server, through the...
1
by: Jay McGrath | last post by:
Help - trying to send a simple text email with with as little user intervention. I am trying to create a button in my Access application that will automatically send a simple text email. It...
2
by: sunilkeswani | last post by:
I would like ms access to send out an email through outlook, with a speicific attachment, to a group of email IDs... Could someone please help with the code? I use MS Acess 2000 & Outlook 2000 ...
2
by: Eric Peterson | last post by:
I need to pop up the send email form from Outlook. I also need to populate the to field, but obviously the user will type the message and hit 'SEND'. How can I do this? I've been through...
2
by: JohnB | last post by:
hi I am using System.Web.Mail.MailMessage to send email. Is there any way to keep the email to "Sent Items" Folder?? I use Microsoft Outlook as my email tool. Thanks
1
by: Mr T | last post by:
I know how to send email from Access and I know how to create a custom form in Outlook. but.... How do I put the email info from Access into the Outlook custom form ??? Dim MyDB As Database Dim...
2
by: Marc Biebauw | last post by:
I would like to send an email with MS Access 97. In our bussiness with don't use MS outlook or MS outlook express. Instead we use teamware. Can anyone help me out with sharing his code on this...
3
by: sentiboy | last post by:
I am using the following code for sending email through mapi in VS 2005 environment: Public objSession As New MSMAPI.MAPISession Public objMessage As New MSMAPI.MAPIMessages ...
2
by: perhapscwk | last post by:
I use below to send email, however, i have 2 mailbox in outllok..it always use the first one to send. How i can set it to set from the other email account? thanks. Sub SendDocumentInMail() ...
1
beacon
by: beacon | last post by:
Hi everybody, I'm sure that everyone cringes when they see "email" in the subject for posts in the forum, but I'm hoping that what I'm trying to do is different enough to present a challenge...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.