Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sending email via VBA code

Posted on 2006-07-13
15
Medium Priority
?
390 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1500 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

Technology Partners: 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!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

604 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