Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2007
    Posts
    214

    Question Unanswered: Two basic questions

    These questions are most likely easy but I'm stumped.

    I have the following code and I need to make two things happen:

    When sending an email, if the email address and the appropriate information is not filled out, I would like a message box to say "Cannot send email, fields not properly filled out" instead of giving me a debug error.

    In the body of the email, it seems I cannot write the contents in paragraphs within vba, it all has to be on one line. Is there a way to enable the different statements in the body of the email be on separate lines?



    im mess_body As String
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)

    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
    .BodyFormat = olFormatRichText
    .To = Me.Contact_for_RFI
    .Subject = "Claim for " & Me.Last_Name & "," & Me.First_Name


    .HTMLBody = "Hello, I hope you are doing well. Can you please provide me with specific details as to why " & Me.Last_Name & ", " & Me.First_Name & " is no longer working for you? They are filing an active claim against " & Me.Employer & " we need specific details to properly contest their claim. Thank you for your help!"









    '.DeleteAfterSubmit = True 'This would let Outlook send th note without storing it in your sent bin
    .Send
    End With
    'MsgBox MailOutLook.Body
    Exit Sub
    email_error:
    MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.DESCRIPTION
    Resume Error_out

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Checking for missing data can be done using code like
    Code:
    If Nz(Me.EmailAddress, "") = "" Then
     Msgbox "Cannot send email without an address!" 
     Exit Sub
    End If
    For formatting the body
    Code:
    HTMLBody = "This is line One." & vbNewLine & "This is line Two." & vbNewLine & "This is line Three."
    will produce

    This is line One.
    This is line Two.
    This is line Three.
    Last edited by Missinglinq; 08-07-10 at 23:43.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Oct 2007
    Posts
    214
    Hello,

    Thanks for your reply. I tried the vbnewline but it still appears on the same line of the email. Is there any other way?

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The ASCII for LineFeed and CarriageReturn should do the same thing:
    Code:
    HTMLBody = "This is line One." & Chr(10) & Chr(13) & "This is line Two." & Chr(10) & Chr(13) & "This is line Three."
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you may also want to validate the email is legit
    ie is comopsed of legit characters AND looks like a email address
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •