Results 1 to 3 of 3
  1. #1
    Soule is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Dec 2011
    Posts
    58

    Automating Access Button To Populate & Send An Outlook Template...Or Two!

    Hello, Everyone - I have a major headache to achieve in the next week. I have two blocks of VBA code, but I'm not sure which one is better for my needs (not to mention what the difference between them is)...



    First...

    I want to create an automated process on an Access form that does the following things for a Human Resources department:
    - (Fields on form are filled out, and the user has come to the "Add Record/Automate" button...
    - <Button is clicked>
    - An Outlook template e-mail to an employee is opened and certain parts of it are populated by certain fields from the form/table.
    - A second Outlook template e-mail to the employee's manager is opened and certain parts of it are populated by certain fields from the form/table.
    - Both Outlook e-mails are sent.

    I have the following blocks of code for one e-mail automation, but I'm not sure how they're different and which one I can adapt to automate two mailings with one button click:

    Dim objFolder As Outlook.MAPIFolder
    Dim objNS As Outlook.NameSpace
    Dim objItems As Outlook.Items
    Dim objNewMail As Outlook.MailItem
    Dim objUPS As Outlook.UserProperties
    Dim objUP As Outlook.UserProperty
    Set objNS = Outlook.GetNamespace("MAPI")
    Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
    Set objItems = objFolder.Items
    Set objNewMail = objFolder.Items.Add("IPM.Note.MyCustomMailForm")
    objNewMail.Subject = "Send Me"
    objNewMail.To = "(E-Mail Removed)"
    Set objUPS = objNewMail.UserProperties
    Set objUP = objUPS.Item("CustomField1")
    objUP.Value = "My Value"
    objNewMail.Send

    AND......

    Dim olApp As Outlook.Application
    Dim olNs As Outlook.NameSpace
    Dim MailBoxFolder As Outlook.MAPIFolder
    Dim itm As Outlook.MailItem
    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set MailBoxFolder = olNs.GetDefaultFolder(olFolderInbox)
    Set itm = MailBoxFolder.Items.Add("IPM.Note.MyTemplate")
    itm.UserProperties.Item("FieldNameHere").Value = "Joe Smith"

    ----

    What is the difference between the ol and obj prefixes? I can recognize similar lines in the two, but don't understand the differences in prefix or where my particular folder/items names should go. Any help would be appreciated! Thanks ahead of time!

    Soule

  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,816
    These are just variables names. You can structure variable names however you want. The 'prefixes' are not even necessary. By convention, obj stands for object and ol stands for Outlook. They cue anyone reading the code what the variable is used for. Usage is good practice but subject to personal preference.
    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
    Soule is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Dec 2011
    Posts
    58
    I forgot to thank you on this one, June! It seems a lifetime ago that I didn't understand variable names! I've been learning VBA while doing an automation project. December...a long time ago in a VBE far, far away!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automating Outlook from Access
    By RMittelman in forum Programming
    Replies: 11
    Last Post: 10-05-2021, 09:57 PM
  2. Open Outlook window but don't send
    By Paul Taylor in forum Access
    Replies: 2
    Last Post: 04-07-2011, 11:51 AM
  3. Send email from Access thru Outlook
    By ZMAN in forum Forms
    Replies: 2
    Last Post: 11-27-2010, 06:10 PM
  4. usings a outlook template
    By kylebmorris in forum Programming
    Replies: 0
    Last Post: 07-19-2010, 01:53 PM
  5. Net Send from a button on an Access form
    By Deb4995 in forum Forms
    Replies: 0
    Last Post: 10-19-2006, 10:19 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