VBA Email Format Problem

Important Notice


Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • Hi All,


    I am working on a document that takes data from A userform field, converts it to HTML and sends the information in an email. I've got everything working really well using lots of help from this website and Ron deBruin's Email code.


    The only niggly problem I have is if a particular field in the userform is left blank, then the email generated still has a blank line and I really want the line to be deleted and the lines below moved up one. An example is here:


    Customer
    Harry's Diner


    Address
    25 Any Street
    <blank line>
    Any Town
    <blank line>
    West Springfield
    AN3 0TH


    What I really want is:


    Customer
    Harry's Diner
    Address
    25 Any Street
    Any Town
    West Springfield
    AN3 0TH


    I've tried putting in a few IF statements to try and get round it but it keeps putting the blank line in because the only code I know how get a blank character is "". This obviously treats the line as blank but still a separate line. Here is the code I have so far.



    I can provide some more supporting code but I'm fairly sure this is where the changes need to be made.


    Can anyone suggest a possible solution? This would sort out the same issue I have with a couple of other project I have as well so any helpful code would be most appreciated.


    Many Thanks as always
    Dave

  • Re: VBA Email Format Problem


    Add a small function to a standard code module


    Then call it passing all the elements of the address in an array

    Code
    "<b>Address:</b><br>" & _ 'Address in Bold
    AddressBlock(Array(txtAdd1.Value, txtAdd2.Value, txtCity.Value, txtCounty.Value))

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!