UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Send Email Using Outlook And Vba, Any Version    
 
   
access2009eg
post Aug 16 2019, 02:48 PM
Post#1



Posts: 1,119
Joined: 19-February 08



Hello Friends

this code is used to send email message

friends
should I set account in the outlook for this code? or not requered

what should I do in my user computer to successfully send email without any error in a user computer


CODE
  Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    
    Set oEmail = oApp.CreateItem(olMailItem)
    
    oEmail.To = Me.txtTo
    oEmail.Subject = Me.txtSubject
    oEmail.Body = Me.txtBody
    If Len(Me.txtAttachment) > 0 Then
        oEmail.Attachments.Add Me.txtAttachment.Value
    End If
    With oEmail
        If Not IsNull(.To) And Not IsNull(.Subject) And Not IsNull(.Body) Then
            .Send
            MsgBox "Email Sent!"
        Else
            MsgBox "Please fill out the required fields."
        End If
    End With

--------------------
I would like to Thank you for your help
Go to the top of the page
 
theDBguy
post Aug 16 2019, 02:56 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,296
Joined: 19-June 07
From: SunnySandyEggo


Hi. I think your code will use the default Outlook profile set up on the user's computer. It will error out if there is no profile set up.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
DanielPineault
post Aug 16 2019, 05:12 PM
Post#3


UtterAccess VIP
Posts: 6,837
Joined: 30-June 11



You need to add proper error handling.
You should be validating that your controls are not Null
You are using Early binding so references can be an issue. You need to ensure you develop using the oldest version of Office that any of your users will be using otherwise you will need to adjust the references manually on those PCs.

I personally prefer a reusable function and using Late Binding to avoid any reference issues. If you are interested, review http://www.devhut.net/2010/09/03/vba-send-...ook-automation/ and http://www.devhut.net/2018/02/16/ms-access...-send-an-email/


QUOTE
should I set account in the outlook for this code? or not requered

If the user has Outlook setup and functional, then it will work as is, like theDBguy stated. If they have multiple accounts, you can always specify which account should be used to perform the send, but typically this isn't required.

--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
access2009eg
post Aug 17 2019, 11:47 AM
Post#4



Posts: 1,119
Joined: 19-February 08



theDBguy

DanielPineault

Thanks for useful information

hat_tip.gif

--------------------
I would like to Thank you for your help
Go to the top of the page
 
theDBguy
post Aug 17 2019, 11:56 AM
Post#5


Access Wiki and Forums Moderator
Posts: 76,296
Joined: 19-June 07
From: SunnySandyEggo


Hi. You're welcome. Daniel and I were happy to assist. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th September 2019 - 11:34 AM