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?
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