I want to send an email using a macro but only once? Access 2010

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Corwin Moyne
    New Member
    • Feb 2012
    • 37

    #1

    I want to send an email using a macro but only once? Access 2010

    Hi there.

    I have a macro set up to send an email when a condition exists. The macro will send when the value in a field is equal or greater than 500,000, but I only want to send this email once. At the minute, everytime the field is updated, because its still over 500,000, the macro sends again. I have tried adding a stopMacro after the if statement but this doesn't appear to do anything?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Corwin Moyne
    Hi there.

    I have a macro set up to send an email when a condition exists. The macro will send when the value in a field is equal or greater than 500,000, but I only want to send this email once. At the minute, every time the field is updated, because its still over 500,000, the macro sends again. I have tried adding a stopMacro after the if statement but this doesn't appear to do anything?
    1. Declare a Private, Form Level, Boolean Variable as such:
      Code:
      Private blnEMailSent As Boolean
    2. Execute Code similar to the following:
      Code:
      If Me![txtTest] > 500000 And Not blnEMailSent Then
        blnEMailSent = True
          MsgBox "Send E-Mail here"
      End If
    3. An E-Mail will only be set if the Value of Me![txtTest] > 500000 AND blnEMailSent = False
    4. By Default, blnEMailSent will be initialized to False, and if the Value is > 500000 it will then be Reset to True and another E-Mail will not be sent unless blnEMailSent is somehow again Reset to False.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Check the before status as well as the after status.

      Only if the after status is > 500,000 and the before status not > 500,000 should you trigger the routine.

      Comment

      • sophina
        New Member
        • Mar 2012
        • 2

        #4
        Thank you ADezii!!! I was looking for hours for this code!!

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          You are quite welcome. Keep in mind that you can Reset the Value of the Variable at any time, and return to the Original State by executing:
          Code:
          blnEMailSent = False

          Comment

          Working...