Link to home
Start Free TrialLog in
Avatar of linder76
linder76

asked on

Sending email via VBA code

I am writing a error routine for a program. My client wants me to write where if the program errors during its run that the error is sent to her cell phone (text message) or email account. Is there a way to do this?

Thank you,

Joe
Avatar of Carl2002
Carl2002

I'm not sure on the test message front but you can definately do it via email.

try:

DoCmd.SendObject [objecttype][, objectname][, outputformat][, to][, cc][, bcc][, subject][, messagetext][, editmessage][, templatefile]

Carl.
Avatar of linder76

ASKER

Thanks, but what is the objects I need to use?
Avatar of rockiroads
By far the simplest is SendObject
if u use this, then credit goes to Carl
this is an example of using it

DoCmd.SendObject , , , "fred@smith.com", , , "My Subject", "My Message - Oh Dear"



There are alternative methods also

Do note, if u have the later versions of Outlook, then u may well get a security message coming up
If u do then look at the answer I gave to, of all people, Carl!   https://www.experts-exchange.com/questions/21904604/Auto-Email-Query-from-Access.html

Note, if u use SendObject, credit goes to Carl, not me

This needs to work without Outlook. It needs to send the message via the code with out user intervention. Is that possible?
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you not use outlook as your email system then?
Carl, who was that question to?

if to me, well then, CDO uses Exchange directly, but I use both Outlook and CDO. I prefer CDO if and when I know the SMTP server, otherwise stick to SendObject or Outlook Auto
I prefer CDO only because of the security check it bypasses
It was to linder76 rocki, but I understand completely why you prefer CDO if it bypasses security after my problem a few days ago
Correct I donot want to use Outlook. This needs to be an automated event.. I am reviewing the comments, what does s/w stand for?
Joe
s/w = software  :-)

I have copy and pasted the code. however the web address when I click on them don't work...also I erase them in the code. Should I be doing that?
I am still haveing problems. I have my reference book with me. What does CDO stand for. I am not familar with it.
I keep getting the following error...

Error in sending. The message could not be sent to the smtp server.

The transport error code was 0x80040217. The server response was not available.

Help????
Thanks for your help! I finally found what I was doing wrong. I needed to add script lines for my account name and password

Joe
CDO = Collaboration Data Objects
its a MS thing
Remember to specify the FROM and SMTP Server also