Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30

    Automated Email using Outlook

    Hi fellows,


    There is some text in a text box named [Message] on a form. What i want to do is to email that text to the email address in text box [EmailAddress] on the same form. What should be the VB code for the Button [Send].

    Thanks in advance. These forums are very helpful for a new and even experienced users.

    Imran

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I have posted this code 3 times in the last 2 days... I hope it helps..




    Code:
    Sub CreateHTMLMail() 
    ''''Creates a new e-mail item and modifies its properties'
    Dim olApp As Outlook.Application 
    Dim objMail As Outlook.MailItem
    
    Set olApp = Outlook.Application 'Create e-mail item' 
    Set objMail = olApp.CreateItem(olMailItem)
    
    ''' Assigning things in the outlook mail message. 
    With objMail
    .Subject = Forms("Formname").txtboxname 
    .Body = Forms("Formname").txtboxname 
    .To = Forms("Formname").txtboxname 
    .Display 
    .ReadReceiptRequested = True 'IF you want to enforce a read receipt, keep this part, if not just comment or remove it End With End Sub

  4. #4
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    I tried that and an error popped up. Here is my code

    Private Sub Command622_Click()


    Sub CreateHTMLMail()


    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem


    Set olApp = Outlook.Application
    Set objMail = olApp.CreatItem(olMailItem)


    With objMail
    .Subject = Forms("Detail").EmailSubject
    .Body = Forms("Detail").EmailMessage
    .To = Forms("Detail").EmailTo
    .Display


    End Sub


    When i removed the first line then after button click nothing happens. Do i have to keep outlook open? and what outlook profile this code will use to send email?

  5. #5
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I'll be in the office in a couple hours. I will double check my code... OHHH add the Microsoft outlook reference library as well... but I will double check when I'm in the office.

  6. #6
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    I did not added Microsoft outlook reference library because i have no idea how to add that. Please help

  7. #7
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Quote Originally Posted by imran688 View Post
    I did not added Microsoft outlook reference library because i have no idea how to add that. Please help
    No problems! Alright
    go into the VBA window (alt+f11)
    Click on Tools then References
    Search for
    Microsoft Outlook XXX object library

    My outlook library is 11.0 but yours might be different.
    Let me know if that works!!!

  8. #8
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    Is my code right?

    Private Sub Command638_Click()


    End Sub
    Sub CreateHTMLMail()


    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem


    Set olApp = Outlook.Application
    Set objMail = olApp.CreatItem(olMailItem)


    With objMail
    .Subject = Forms("Detail").EmailSubject
    .Body = Forms("Detail").EmailMessage
    .To = Forms("Detail").EmailTo
    .Display


    End Sub

  9. #9
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    So when you click the button, nothing is happening at this point correct??

    Try this..

    Private Sub Command638_Click()

    Call CreateHTMLMail

    End Sub


    Sub CreateHTMLMail()


    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem


    Set olApp = Outlook.Application
    Set objMail = olApp.CreatItem(olMailItem)


    With objMail
    .Subject = Forms("Detail").EmailSubject
    .Body = Forms("Detail").EmailMessage
    .To = Forms("Detail").EmailTo
    .Display
    End Sub

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Looks good. You can test it. Since the code is set to just display the Outlook email, no harm will be done.

    Use debug techniques explained in link at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    June, quick question.. not on topic at all.. but I don't want to make an entire thread about it...
    I am trying to Flip visibility on a label box. The code is in a module and NOT behind the form...

    Is this something that can be done? I have tried...

    Forms("frmmainnew").lblVerfied.visable = True

    But its not changing the property... I've done this behind the form code in the past without issue.

  12. #12
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    Still this error "Compile Error: Expected end with"
    Attached Thumbnails Attached Thumbnails Email.jpg  

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Imran688:
    Every 'With' needs an 'End With', in this case just above the 'End Sub'


    Redbull:

    Should be possible. You show the word 'Visible' misspelled but that should produce a compile error. Is 'lblVerfied' correct spelling or should it be 'lblVerified'?

    Try alternate syntax:

    Forms!frmmainnew.lblVerfied.Visible = True

    or

    Form_frmmainnew.lblVerfied.Visible = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    Its working. Awesome.
    Thanks a lot

  15. #15
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    oh. Its this error now
    Attached Thumbnails Attached Thumbnails Email.JPG  

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automated Data Collection Through Email Trouble
    By drexasaurus in forum Import/Export Data
    Replies: 4
    Last Post: 10-17-2014, 12:39 PM
  2. Automated Email Notification
    By sai_rlaf in forum Access
    Replies: 5
    Last Post: 12-07-2011, 06:33 PM
  3. automated email sent from records in form
    By hmcquade in forum Forms
    Replies: 2
    Last Post: 05-23-2011, 08:45 AM
  4. Automated email from access
    By jfuller in forum Access
    Replies: 3
    Last Post: 04-11-2011, 02:56 PM
  5. Replies: 1
    Last Post: 03-02-2010, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums