Solved

Sending email via VBA code

Posted on 2006-07-13
15
375 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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