Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Search Search
Search for:
Tech Support Guy > > >

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


(!)

axkoam's Avatar
axkoam axkoam is offline
Member with 22 posts.
THREAD STARTER
 
Join Date: Jun 2012
Experience: Beginner
03-Aug-2012, 01:22 PM #1
Solved: Sending an automated email, including a possible error message
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
axkoam's Avatar
axkoam axkoam is offline
Member with 22 posts.
THREAD STARTER
 
Join Date: Jun 2012
Experience: Beginner
03-Aug-2012, 03:34 PM #2
Someone on a different forum gave me this, which worked great:

Code:
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

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2