Automated Mail Delivery Time Using Table Data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elak6
    New Member
    • Nov 2011
    • 21

    Automated Mail Delivery Time Using Table Data

    Good Day,
    I have an access database
    I want to be able to send a reminder email to myself every 3 months
    So basicall when today date vs last update date in my table > 30
    Then automically send email
    At the moment i am using the deferred delivery time method..
    But i would prefer a way to calculate the difference between todays date vs last update date in my table and if >30.
    Then today's date is passed a s the parameter for the deferred delivery time
    Thanks
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    So, what have you got already?

    What do you want help with?

    Why would you want to set a deferred date if that is the same date as you run the code?

    There's a hint of a question here but it's not very clear. I seem to recall deleting a/some questions from you already with instructions to make more sense, so I'm guessing this is the best you can do. We're good with honest attempts, but you need to answer these three questions to allow us to help you formulate a sensible question that we can help with.

    Comment

    • elak6
      New Member
      • Nov 2011
      • 21

      #3
      Thanks for the reply NeoPa
      The main aim of having a deffered date is that i want a reminder email to be generated every 3 months without any inut from me to remind to update sections of my database
      What i really wan
      The deffered date is not the same date i run the code
      The code is going to run continually everyday
      But what i really want is that that i set a date as a benchmark and 30 days adter that benchamrk date, the reminder mail is sent out to me. and then the benchamrk date is refereshed and set to the day the emial was sent out and another 30 days countdown begins.
      I tried using the deffered delivery method and just settin ti 30 days from now but this dosent work because it would mean that i would have to continoulsy go back and edit the deferred delivery time again to the next 30 days which totallydefeats the whole purpose of automation
      I am sorry if my earlier post was not very understandable
      Thanks for all your help

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Elak, when your question doesn't make sense it's often because you don't focus on the problem very clearly. In that case, it often helps if someone, who is able to think more clearly, posts some questions for you to answer, as the answers to those questions often clarify the question (Indeed, the questions are chosen specifically for that purpose). That makes it very important that you answer those questions as well as you can. Further explanations without the questions answered, is frankly not very likely to be of much help (As in this case) as if you were able to explain it clearly one would assume you'd have done it originally.

        I suggest then, answering the questions would be the first thing you do after reading this post.

        There are more things to consider, but without that basic question sorted out my explanations will make little sense I suspect.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Some more things to consider (but not at the expense of answering those questions) :
          1. Presumably we're talking about Outlook here. There is no item I know of which sends an email every 30 days, so this cannot be set up once and left to run automatically without code.
          2. One consideration should be recurring appointments. An Outlook Appointment can be set up to remind you every 30 days. Set it once and it will continue working forever. No work or code required after that. It's what I'd do in your situation (or at least as much of your situation that has been explained).
          3. Assuming that's not a viable solution then let's look at what might be :
            1. If the code is run every day (so the Access database is opened by you every working day) then what is the benefit of setting up the email in advance? It would surely be easy (if only in your understanding of it) to determine the dates within Access and send an email when the 30th day has been reached (or passed if you allow for weekends or holidays).
            2. Alternatively, you could set up some code, triggered by a specific Command Button on a specific form, which sets up an email deferred for 30 days, and you only ever run this process on the day you read the previously sent email.


          Does that about sum things up?

          Think about all these and say where you think you're heading.

          PS. Don't forget to read all posts since you last posted, and not just the one at the end. Sometimes more than one post are there to be read.

          Comment

          • elak6
            New Member
            • Nov 2011
            • 21

            #6
            Dear Neopa,
            I appreciate the fact that you are not getting paid for this service and you are doing all of us a favour. I do know it can be very frustrating when you are trying to help people and sometimes their question just contain too much dilly-dallying and not getting straight to the point but some of your comments in post 4 were quite hurtful.
            I guess it's my fault cuz i went in to much detail thinking it would aid the whole process
            I just wanted an access vba to send out an email reminder every 30 days automatically..
            So far i have been able to send out emails automatically from access and also been able to specify the date and times i want the email sent using the deferred delivery time in access vba
            My problem presently is creating a reoccurring reminder every 30 days..i don't know how to go about this
            Thanks for all the help you have given to me
            Regards,
            elak
            Last edited by elak6; Dec 5 '11, 10:05 PM. Reason: needed more detail

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32661

              #7
              Originally posted by Elak6
              Elak6:
              but some of your comments in post 4 were quite hurtful.
              I don't have very long hair (Less than 1cm) yet I still find myself trying to pull it out. Luckily I can't get a good grip.

              I think I'd settle for a little hurtful if only I could get you to pay attention to what I'm saying. Because I'm self-opinionated? Vain? Full of myself? All possibles, but in fact no. Because I think I can help you, but every time I post anything that isn't what you want/expect to see, you seem to avoid seeing it (and just ignore it). I have already included in my posts so far what I think are answers to your actual problem, but because you are trundling along with your mind closed you haven't seen them. You certainly haven't yet (even now) answered any of the three questions in post #2. Is that better manners than my being a little hurtful?

              Whether or not, I am actually sorry you feel hurt (and, by inference, that I caused that hurt). Normally I find people who take that much kicking to pay attention, are pretty thick-skinned. I only wanted to get you to start thinking and getting more involved in what is, after all, your own question thread.

              Originally posted by Elak6
              Elak6:
              My problem presently is creating a reoccurring reminder every 30 days..i don't know how to go about this
              As I've already addressed this point in one of my earlier posts I would suggest you read back through the thread again for yourself. You might find more there than you realise. If, after that, you still need more help, then all I ask is that you engage with me in the discussion. I pay attention to all you post. I simply ask that you do me the same courtesy. I'm confident under those circumstances I can express all that I know on the subject and thus be a lot more help to you.

              PS. I am sometimes considered abrasive, and I often post very directly. However, my intention is not to be hurtful and I will take more care with you particularly in future.

              Comment

              • elak6
                New Member
                • Nov 2011
                • 21

                #8
                Hi NeoPa

                Thanks for your reply and I am sorry if my earlier post offended you.
                I finally understand what you mean more clearly
                I think the frustration of the code not working out was clouding my thinking and do I apologize for any inconveniences I have caused you and i really appreciate all your help

                I did read your post and you suggested you using an outlook reminder without code
                Let me give you a background about that the database, hopefully this would help you understand my questions better
                I am creating a database on behalf of some managers who do not have any access expertise at all
                The database is going to be a shared one
                I could create a reminder via outlook but that would mean that I have to set it up on each mangers pc, which is not viable

                To answer your questions.
                What have I got already: I am able to send out emails to all managers by clicking a command button/or by running a code on my form
                I also incorporated (.DeferredDeliv eryTime), this was so as to enable me to run the code at a specific time..I now realize that this is not a very wise method to use

                What do I want help with: I want to be able to set up a way to send out emails to all managers automatically every 3 months..I know that for this to occur their outlook and the database needs to be open for the code to run..
                In you earlier post you suggested:
                the code is run every day (so the Access database is opened by you every working day) then what is the benefit of setting up the email in advance? It would surely be easy (if only in your understanding of it) to determine the dates within Access and send an email when the 3 month period has elapsed
                This is what I had in mind initially and I have set the dates but my problem is after the 3 month period has elapsed, how do I refresh and start another 3 month period countdown after the first one has elapsed
                I am aiming for this whole process to be automated because the managers who will have no knowledge of access and so cant make any changes to the database

                An clip/snapshot of the code I have:
                Code:
                .Subject = "Testing Automation"
                .Body = "this might work and so could this"
                .DeferredDeliveryTime = Me.NextUpdate
                .DeleteAfterSubmit = True  'Deletes message after it has been sent, so that no record is present in your access folder
                The Next Update is just a textbox on my form that I put in the date of the next update which is in 3 months, so for example I put in March 06 2012
                My problem is I don’t want to manually put in the date, I just want the computer to count a 3 month period and on the last day of that period, send the email ,and from that days onwards another 3 month countdown begins.

                You also suggested an alternative method of setting up an email which is deferred for 30 days and the process is only ran on the days the previously sent email is read.. How do I go about implementing this?

                Hopefully this explains everything better and sorry for making you try to pull out your hair :(
                Last edited by elak6; Dec 6 '11, 09:04 AM. Reason: Typographical errors and poor formatting

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32661

                  #9
                  Where do I start? Let me start by saying Hello Elak6 :-) It's so nice to meet the real you at last. And may I add a little impressive. I was hoping for something I could start working with productively, but what I see is far more than that. Fully engaged at an intelligent level. I hope that together we can illustrate how much you can benefit from the different approach.

                  I wasn't offended by anything you said. Frustrated at times yes, but there was no offense. I never saw anything that indicated you were attempting to be rude or abusive. Your last post made up for all that though anyway.

                  Back to your question :

                  It seems to me that either of the last two options (Send with defer, or wait and send) would still suit your purposes as long as you could determine when to trigger the process again without duplicating any of the emails. I believe the first step to understanding this is to maintain a table in your database which contains the date of the last email sent (or the Deferred Send Date if that option is preferred). Every day, when you open the database, it should check this field (which I'll call [SendDate] for reference) and determine what to do based on the value :
                  Code:
                  [B][U]Status of Date()   Send Now Option  Send Deferred Option[/U][/B]
                  <[SendDate]        Nothing          Nothing
                  =[SendDate]        [U][B]Process A[/B][/U]        Nothing
                  >[SendDate]        Nothing          [U][B]Process B[/B][/U]
                  Process A
                  • Update [SendDate] by 30 days.
                  • Send e-mails to all recipients (No deferral).

                  Process B
                  • Update [SendDate] by 30 days.
                  • Send e-mails to all recipients with deferral to newly calculated [SendDate].


                  Does that sound like it could work for you?

                  PS. All hair still in place. Cutting it short is a very effective safety device :-D
                  Last edited by NeoPa; Dec 6 '11, 05:16 PM. Reason: Reformatted for clarity

                  Comment

                  • elak6
                    New Member
                    • Nov 2011
                    • 21

                    #10
                    Hi NeoPa,

                    Thanks for the reply
                    I think the best approach to this matter is the one you suggested above
                    There are just some points that I don’t understand fully

                    I am guessing if I was to write the VBA code, it will be something like:

                    Code:
                    If Date  < Send Date
                    Then Do Nothing 
                    ElseIf
                    Date= Send Date
                    Then Call Command Msg    ‘which is the command that allows the message to be sent automatically
                    Send Date = Send Date +30   ‘so the send date is updated for the next 30 days
                    [I]ElseIf
                    Date > Send Date
                    Then  
                    .DeferredDeliveryTime =Send Date + 30[/I]
                    End If
                    Where I am a bit confused is that last table row/last if statement which is in italics

                    This piece of code assumes that a situation will arise that the send date would be in the past compared to the present date but if the code works according to the way we want, this bit of code will never be needed because such a situation will never occur because the send date will always be in the future(initiall y) or will be set to a future date automatically if date=send date.

                    Also I am relatively new to access, so the question I am about to ask is going to be quite dumb..Sorry :(
                    How will I reference a field/row in a table in VBA code..like if I want to put reference to a specific cell in a table, how do I do that in VBA code
                    Also if the send date is a text box or cell in a table, am I able to update (i.e. send date = send date +30) automatically from visual basic

                    Thanks for all your help
                    Really appreciate it
                    Last edited by elak6; Dec 7 '11, 10:25 AM. Reason: poor formatting

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32661

                      #11
                      This is fun. Seriously. By your engaged questions I have a much clearer understanding of what, and how, you need things explained. Such responses aren't dumb in the least. They are illuminating and, because of that, very helpful.

                      Now, to follow that, I am going to deviate from the normally sensible course of answering each question individually, as I think a slightly different approach will answer many of your questions incidentally, and from there you can explain what, if anything, you're still unclear on.

                      First of all, when approaching something like this, we need to consider what triggers the code to run. There is an article (Invoking a Database From the Command Line) which deals with opening a database automatically, and within there it explains how to run code from a form which opens automatically once the database is opened. This may be worth some consideration. How much of that you need I don't know (It seems already you are opening the database every day anyway, but I expect running this form/code automatically when the database opens would be useful).

                      From this point, I would be looking at a form bound to this special table with the [SendDate] field in it (as a bound TextBox). What this approach gives us is an easy approach to both displaying and updating the value of this field. The Form_Open() event procedure would be where the code would exist and be run from.

                      The code itself should be fairly straightforward from here, but would differ depending on the approach you choose from the two identified (With or without deferral), but should be something like :

                      Code:
                      Private Sub Form_Open(Cancel As Integer)
                      ' Comment out inappropriate lines for the option chosen
                          With Me
                              If Date >= .txtSendDate Then     ' Now option
                              If Date > .txtSendDate Then      ' Deferred option
                                  .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
                                  Call RunCommand(acCmdSaveRecord)
                                  Call YourSendEMailsProc()
                              End If
                              ' If you want the operator to see the status leave this as is, otherwise
                              Call DoCmd.Close
                          End With
                      End Sub
                      PS. Assuming you don't work (and thereby open the database) on weekends and/or holidays it's perfectly feasible to find that the day the email was due was a day when the database was not opened. Hence it is necessary to consider (and handle) the possibility of today being greater than [SendDate] even when the logic would normally ensure that doesn't happen.

                      Let us know how far you get with this and what, if anything, still confuses you.
                      Last edited by NeoPa; Dec 7 '11, 04:44 PM.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32661

                        #12
                        Actually, I found that didn't work when run from the Open event procedure, so I had to move the meat of it to the Timer event procedure :

                        Code:
                        Option Compare Database
                        Option Explicit
                        
                        Private Sub Form_Open(Cancel As Integer)
                        ' Comment out inappropriate lines for the option chosen
                            With Me
                                If Date < .txtSendDate Then     ' Now option
                                'If Date <= .txtSendDate Then      ' Deferred option
                                    Cancel = True
                                    Exit Sub
                                End If
                                .OnTimer = "[Event Procedure]"
                                .TimerInterval = 50
                            End With
                        End Sub
                        
                        Private Sub Form_Timer()
                            With Me
                                .TimerInterval = 0
                                .OnTimer = ""
                                .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
                                ' Call RunCommand(acCmdSaveRecord) doesn't work here
                                .Dirty = False    ' Has the same effect as line above and saves record
                                Call YourSendEMailsProc
                                ' If you want the operator to see the status exit now, otherwise
                                Call DoCmd.Close
                            End With
                        End Sub

                        Comment

                        • elak6
                          New Member
                          • Nov 2011
                          • 21

                          #13
                          Hi NeoPa,

                          Sorry for the long delay in replying, i was bogged down with work
                          I was able to sucessfuly implement it using the method you suggested
                          Thanks so much for you all help and once again, sorry for all the stress i have you

                          This is the code which i used below:-
                          Code:
                          Private Sub Form_Open(Cancel As Integer)
                          With Me
                          If Date < NextUpdate Then
                          RetValue = MsgBox("NextUpdate is in the future", vbInformation)
                          ElseIf Date >= NextUpdate Then
                          Call happy
                          RetValue = MsgBox("NextUpdate is now", vbInformation)
                          Call SendMsg
                          .NextUpdate = DateAdd("d", 30, CDate(NextUpdate))
                          Cancel = True
                          End If
                          End With
                          End Sub

                          .Although i do have a few question sorry:(
                          The section of the code highlighted below, i dont really understand what it does
                          Code:
                          Private Sub Form_Timer() 
                              With Me 
                                  .TimerInterval = 0 
                                  .OnTimer = "" 
                                  .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate)) 
                                  ' Call RunCommand(acCmdSaveRecord) doesn't work here 
                                  .Dirty = False    ' Has the same effect as line above and saves record 
                                  Call YourSendEMailsProc 
                                  ' If you want the operator to see the status exit now, otherwise 
                                  Call DoCmd.Close 
                              End With 
                          End Sub

                          Kind Reagrds,
                          elak6

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32661

                            #14
                            Lines #4 & #4 disable the timer event triggering the procedure again.
                            Line #5 adds 30 days to the date shown in txtSendDate.
                            Line #7 saves the change just made.
                            Line #8 is the code you already said you had working.
                            Line #10 is optional but closes the form if used.

                            There is some code that's missing from there too (my mistake). I will update later but just rushing out the door now.

                            PS. In the mean time try to work out what else is needed. The main issue is turning the timer procedure trigger back on.
                            Last edited by NeoPa; Dec 12 '11, 05:54 PM.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32661

                              #15
                              I include a revised version below to handle re-enabling the timer procedure after your emailing code has completed execution :

                              Code:
                              Private Sub Form_Timer()
                                  Dim lngTI As Long
                              
                                  With Me
                                      lngTI = .TimerInterval
                                      .TimerInterval = 0
                                      .OnTimer = ""
                                      .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
                                      ' Call RunCommand(acCmdSaveRecord) doesn't work here
                                      .Dirty = False    ' Has the same effect as line above and saves record
                                      Call YourSendEMailsProc
                                      .TimerInterval = lngTI
                                      .OnTimer = "[Event Procedure]"
                                  End With
                              End Sub

                              Comment

                              Working...