Results 1 to 4 of 4
  1. #1
    axkoam is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    6

    Sending an automated email, including a possible error message


    Views: 4 Size: 1.2 KB">code.txt
    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 = olToOn Error GoTo ErrMsg     Set objOutlookRecip = .Recipients.Add(Forms!Form1.Text83.Value)      objOutlookRecip.Type = olTo      Exit SubErrMsg:      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 = NothingEnd Sub
    I can't get my code it look clean in the post for some reason, try looking at my .txt attachment

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your code is unreadable, but as answered elsewhere:

    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
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    axkoam is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    6
    Thanks that worked.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automated Data Collection Through Email Trouble
    By drexasaurus in forum Import/Export Data
    Replies: 4
    Last Post: 10-17-2014, 12:39 PM
  2. Automated Email Notification
    By sai_rlaf in forum Access
    Replies: 5
    Last Post: 12-07-2011, 06:33 PM
  3. automated email sent from records in form
    By hmcquade in forum Forms
    Replies: 2
    Last Post: 05-23-2011, 08:45 AM
  4. Automated email from access
    By jfuller in forum Access
    Replies: 3
    Last Post: 04-11-2011, 02:56 PM
  5. Replies: 1
    Last Post: 03-09-2006, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums