1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Sending an automated email, including a possible error message

Discussion in 'Business Applications' started by axkoam, Aug 3, 2012.

Thread Status:
Not open for further replies.
  1. axkoam

    axkoam Thread Starter

    Jun 4, 2012
    I'm having trouble getting this automated email to send. I want it to prompt the MsgBox to the user if the Forms!Form1.Text83.Value yields an error (i.e. that field is null), but if it's not null I want the procedure to send the email.
    What's happening with my code below is that when the Forms!Form1.Text83.Value is null, it will prompt the message AND send the email, and when Forms!Form1.Text83.Value isn't null it will do nothing.
    How can I make it just display the message box when null, and just send the email when it isn't null?

    Private Sub SendMessage()
       Dim objOutlook As Outlook.Application
       Dim objOutlookMsg As Outlook.MailItem
       Dim objOutlookRecip As Outlook.Recipient
       'Dim objOutlookAttach As Outlook.Attachment
       Set objOutlook = CreateObject("Outlook.Application")
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
       With objOutlookMsg
         Set objOutlookRecip = .Recipients.Add("*removed for privacy*")
          objOutlookRecip.Type = olTo
    On Error GoTo ErrMsg
         Set objOutlookRecip = .Recipients.Add(Forms!Form1.Text83.Value)
          objOutlookRecip.Type = olTo
          Exit Sub
          MsgBox "Please enter your e-mail into into the Form1 textbox labeled 'User E-Mail'"
          .Subject = "MISSING Routing Information!"
          .Body = "Please follow the link below to the F_Routing Form to fill in the email address for each Mfg_Cd that is listed:" & vbCrLf & vbCrLf & PathToFrontEnd
          .Importance = olImportanceHigh
          For Each objOutlookRecip In .Recipients
             If Not objOutlookRecip.Resolve Then
          End If
       End With
       Set objOutlookMsg = Nothing
       Set objOutlook = Nothing
    End Sub
  2. axkoam

    axkoam Thread Starter

    Jun 4, 2012
    Someone on a different forum gave me this, which worked great:

    If Len(Forms!Form1.Text83 & vbNullString) = 0 Then  MsgBox "You need to fill out the address"Else  'your code here to send the emailEnd If
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1063706

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice