Solved

Sending email via VBA code

Posted on 2006-07-13
15
365 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:linder76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 4

Expert Comment

by:Carl2002
ID: 17100420
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.
0
 

Author Comment

by:linder76
ID: 17100431
Thanks, but what is the objects I need to use?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17100476
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!   http://www.experts-exchange.com/Databases/MS_Access/Q_21904604.html

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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:linder76
ID: 17100489
This needs to work without Outlook. It needs to send the message via the code with out user intervention. Is that possible?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17100504
If u install that s/w called Click Yes, then that may do it for u - no user intervention

DoCmd.SendObjects will use Outlook if u have that installed


If u know your SMTP address, u can use CDO


Public Function SendEmailCDO(ByVal strTo As String, _
                          ByVal strMessage As String, _
                          ByVal strSubject As String, _
                          Optional ByVal strAttach As String)

    Dim objEmail As Object
   
   
    On Error Resume Next
   
    Set objEmail = CreateObject("CDO.Message")
    '**** email address of sender
    objEmail.From = "fred@smith.com"      
    objEmail.To = strTo
    objEmail.Subject = strSubject
    objEmail.TextBody = strMessage
    if strAttach <> "" then objEmail.AddAttachment strAttach
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    '**** smtp.xxx.com - here u enter your smtp server name, whatever that is
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.xx.com"

    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    If Err.Number <> 0 Then
        MsgBox "Error in sending. " & Err.Description
    Else
        MsgBox "Sent"   'remove this if u dont want confirmation
    End If
    Set objEmail = Nothing

End Function
0
 
LVL 4

Expert Comment

by:Carl2002
ID: 17100514
Do you not use outlook as your email system then?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17100660
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
0
 
LVL 4

Expert Comment

by:Carl2002
ID: 17100675
It was to linder76 rocki, but I understand completely why you prefer CDO if it bypasses security after my problem a few days ago
0
 

Author Comment

by:linder76
ID: 17101428
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
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 17101596
s/w = software  :-)

0
 

Author Comment

by:linder76
ID: 17101615
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?
0
 

Author Comment

by:linder76
ID: 17101672
I am still haveing problems. I have my reference book with me. What does CDO stand for. I am not familar with it.
0
 

Author Comment

by:linder76
ID: 17101811
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????
0
 

Author Comment

by:linder76
ID: 17103929
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17103954
CDO = Collaboration Data Objects
its a MS thing
Remember to specify the FROM and SMTP Server also

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question