Sending an automated email, including a possible error message (1 Viewer)

axkoam

New member
Local time
Today, 03:55
Joined
Jun 19, 2012
Messages
7
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?

Code:
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
ErrMsg:
      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
         objOutlookRecip.Resolve
         If Not objOutlookRecip.Resolve Then
         objOutlookMsg.Display
      End If
      Next
      .Send
   End With
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:55
Joined
Aug 30, 2003
Messages
36,128
I would do this:

Code:
If Len(Forms!Form1.Text83 & vbNullString) = 0 Then
  MsgBox "You need to fill out the address"
Else
  'your code here to send the email
End If
 
Last edited:

axkoam

New member
Local time
Today, 03:55
Joined
Jun 19, 2012
Messages
7
Great, thanks so much.
 

Users who are viewing this thread

Top Bottom