Results 1 to 7 of 7
  1. #1
    catluvr is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2018
    Location
    Kansas
    Posts
    87

    Change the "Dot" Methods With Outlook Email Item

    Hello All!



    I have a form where users can select multiple options for creating an email.

    I help manage an annual Day Camp and I'm updating some of the code during the "off season".

    One of my responsibilities is to keep the unit leaders up-to-date with roster changes.

    I have code that lets me choose whether or not to include a table of the unit members in the body of the email; whether or not to attach a pdf of the roster; and whether or not the pdf roster should be the roster that's already been run or if a new roster should be run.

    Each combination of options is used in a number of "Select Case" statements.

    I'd like to streamline the code so I don't have to make changes in as many places.

    Is there a way to switch between methods or turn them on and off?

    For example, if the pdf file should be attached, the snippet of code would be:
    **Note: this code is a very simplified version of what I have; in reality, there is code before this selecting the correct email; determining the file to use; and building the body of the email.
    **There are also several other methods included in the With statements.
    **The code that I have works with no issues, I'm just trying to reduce things

    Code:
    With EmailItem
    
        .To = UL_email
        .Subject = SubjText
        .HTMLBody = MsgText
        .Attachments.Add FileName
        .Display
    
    End With
    If I don't want to include the pdf file, I have a copy the entire code with the attachments method commented out:

    Code:
    With EmailItem
    
        .To = UL_email
        .Subject = SubjText
        .HTMLBody = MsgText
        '.Attachments.Add FileName
        .Display
    
    End With
    Is there any VBA code add or remove the ".Attachements.Add FileName" bit?

    That way, if something in the With statement, I won't need to change it several places (and missing one or two and screwing everything up!!)


    Edited to add:
    And, if there is a way to do this, where in the overall code should I put it??


    Thank You!


    Susie
    Girl Scout Volunteer
    Kansas

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I don't usually like to write statements that don't apply to the object in a With block but I guess this could be an exception. Untested, but perhaps
    Code:
    With EmailItem
      .To = UL_email
      .Subject = SubjText
      .HTMLBody = MsgText
      If SomeFunction Then
         .Attachments.Add FileName
      End If
      .Display
    End With
    Where SomeFunction returns True or False. Perhaps using your Select block code or just a separate test for whatever it determines to include/exclude any property of the email object.
    Last edited by Micron; 09-09-2021 at 12:25 PM. Reason: code correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    catluvr is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2018
    Location
    Kansas
    Posts
    87
    Oh geez! I'm clueless ... !

    An "If/Then/Else" statement ... so easy!

    Works perfectly!

    Thank you so very much!

    Susie
    Kansas

    ( "Raisin Awareness" Hee Hee!)

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Glad to help where I can.
    I thought about just

    .HtmlBody...
    If SomeFunction Then .Attachments.Add fileName
    .Display

    but opted for the Else in case another option was required besides just attaching or not attaching the file.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    deleted duplicate post (how dat happin?)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    catluvr is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2018
    Location
    Kansas
    Posts
    87
    Ah! The Microsoft website : https://docs.microsoft.com/en-us/off...i/access.docmd referred to the things after the dots as "methods," so I went with that.

    I'll use "properties" from now on!

    Thanks again,


    Susie
    Kansas

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    That's the DoCmd object, which only has methods so that is correct. Your posts never showed you using that, just what I took to be the MailItem object that you assigned to a variable named EmailItem. Kind of implied in your post title too.

    What follows the dot can be a property, method or object reference. If there are other possibilities, they are not coming to me at the moment.
    Last edited by Micron; 09-09-2021 at 01:16 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. eMail Addresses Not "Resolving" in Outlook
    By dashiellx in forum Programming
    Replies: 10
    Last Post: 01-25-2019, 01:04 PM
  2. Replies: 2
    Last Post: 02-14-2016, 11:19 AM
  3. Replies: 4
    Last Post: 09-10-2015, 08:22 AM
  4. Replies: 1
    Last Post: 12-10-2013, 12:59 AM
  5. Change outlook "From" Address
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 05-25-2011, 12:35 PM

Tags for this Thread

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