469,341 Members | 6,291 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

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
Dec 5 '11 #1
20 3410
32,182 Expert Mod 16PB
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.
Dec 5 '11 #2
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
Dec 5 '11 #3
32,182 Expert Mod 16PB
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.
Dec 5 '11 #4
32,182 Expert Mod 16PB
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.
Dec 5 '11 #5
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
Dec 5 '11 #6
32,182 Expert Mod 16PB
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.

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.
Dec 5 '11 #7
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 (.DeferredDeliveryTime), 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:
Expand|Select|Wrap|Line Numbers
  1. .Subject = "Testing Automation"
  2. .Body = "this might work and so could this"
  3. .DeferredDeliveryTime = Me.NextUpdate
  4. .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 :(
Dec 6 '11 #8
32,182 Expert Mod 16PB
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 :
Expand|Select|Wrap|Line Numbers
  1. Status of Date()   Send Now Option  Send Deferred Option
  2. <[SendDate]        Nothing          Nothing
  3. =[SendDate]        Process A        Nothing
  4. >[SendDate]        Nothing          Process B
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
Dec 6 '11 #9
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:

Expand|Select|Wrap|Line Numbers
  1. If Date  < Send Date
  2. Then Do Nothing 
  3. ElseIf
  4. Date= Send Date
  5. Then Call Command Msg    ‘which is the command that allows the message to be sent automatically
  6. Send Date = Send Date +30   ‘so the send date is updated for the next 30 days
  7. ElseIf
  8. Date > Send Date
  9. Then  
  10. .DeferredDeliveryTime =Send Date + 30
  11. 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(initially) 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
Dec 7 '11 #10
32,182 Expert Mod 16PB
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 :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. ' Comment out inappropriate lines for the option chosen
  3.     With Me
  4.         If Date >= .txtSendDate Then     ' Now option
  5.         If Date > .txtSendDate Then      ' Deferred option
  6.             .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
  7.             Call RunCommand(acCmdSaveRecord)
  8.             Call YourSendEMailsProc()
  9.         End If
  10.         ' If you want the operator to see the status leave this as is, otherwise
  11.         Call DoCmd.Close
  12.     End With
  13. 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.
Dec 7 '11 #11
32,182 Expert Mod 16PB
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 :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Private Sub Form_Open(Cancel As Integer)
  5. ' Comment out inappropriate lines for the option chosen
  6.     With Me
  7.         If Date < .txtSendDate Then     ' Now option
  8.         'If Date <= .txtSendDate Then      ' Deferred option
  9.             Cancel = True
  10.             Exit Sub
  11.         End If
  12.         .OnTimer = "[Event Procedure]"
  13.         .TimerInterval = 50
  14.     End With
  15. End Sub
  17. Private Sub Form_Timer()
  18.     With Me
  19.         .TimerInterval = 0
  20.         .OnTimer = ""
  21.         .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
  22.         ' Call RunCommand(acCmdSaveRecord) doesn't work here
  23.         .Dirty = False    ' Has the same effect as line above and saves record
  24.         Call YourSendEMailsProc
  25.         ' If you want the operator to see the status exit now, otherwise
  26.         Call DoCmd.Close
  27.     End With
  28. End Sub
Dec 7 '11 #12
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:-
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. With Me
  3. If Date < NextUpdate Then
  4. RetValue = MsgBox("NextUpdate is in the future", vbInformation)
  5. ElseIf Date >= NextUpdate Then
  6. Call happy
  7. RetValue = MsgBox("NextUpdate is now", vbInformation)
  8. Call SendMsg
  9. .NextUpdate = DateAdd("d", 30, CDate(NextUpdate))
  10. Cancel = True
  11. End If
  12. End With
  13. End Sub

.Although i do have a few question sorry:(
The section of the code highlighted below, i dont really understand what it does
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer() 
  2.     With Me 
  3.         .TimerInterval = 0 
  4.         .OnTimer = "" 
  5.         .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate)) 
  6.         ' Call RunCommand(acCmdSaveRecord) doesn't work here 
  7.         .Dirty = False    ' Has the same effect as line above and saves record 
  8.         Call YourSendEMailsProc 
  9.         ' If you want the operator to see the status exit now, otherwise 
  10.         Call DoCmd.Close 
  11.     End With 
  12. End Sub 

Kind Reagrds,
Dec 12 '11 #13
32,182 Expert Mod 16PB
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.
Dec 12 '11 #14
32,182 Expert Mod 16PB
I include a revised version below to handle re-enabling the timer procedure after your emailing code has completed execution :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2.     Dim lngTI As Long
  4.     With Me
  5.         lngTI = .TimerInterval
  6.         .TimerInterval = 0
  7.         .OnTimer = ""
  8.         .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
  9.         ' Call RunCommand(acCmdSaveRecord) doesn't work here
  10.         .Dirty = False    ' Has the same effect as line above and saves record
  11.         Call YourSendEMailsProc
  12.         .TimerInterval = lngTI
  13.         .OnTimer = "[Event Procedure]"
  14.     End With
  15. End Sub
Dec 13 '11 #15
Hi Neopa,
Thanks for all your help
I ran the code posted above but i seem to be encountering a problem
Everytime i close the form and then reload it, it never saves the value of the next update text box
Please can you help
Dec 19 '11 #16
32,182 Expert Mod 16PB
I don't understand why that would be the case if you used the code I suggested. Can you post the code you're using for me to look at.
Dec 19 '11 #17
Hi Neopa,
Happy New Year to you and hope you had a good holiday
I ran the code exactly as you put it and it is still giving me errors. The code i ran is shown below:-

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     With Me
  3.         If Date = .txtSendDate Then     ' Now option
  4.         If Date <> .txtSendDate Then      ' Deferred option
  5.         RetValue = MsgBox("NextUpdate is in the future/past", vbInformation)
  6.             Cancel = True
  7.             Exit Sub
  8.         End If
  9.         End If
  10.         .OnTimer = "[Event Procedure]"
  11.         .TimerInterval = 50
  12.     End With
  13. End Sub

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2.     Dim lngTI As Long
  4.     With Me
  5.         lngTI = .TimerInterval
  6.         .TimerInterval = 0
  7.         .OnTimer = ""
  8.         '.txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
  9.         .txtSendDate = DateAdd("d", 30, (.txtSendDate))
  10.         ' Call RunCommand(acCmdSaveRecord) doesn't work here
  11.         .Dirty = False    ' Has the same effect as line above and saves record
  12.         Call coke
  13.         .TimerInterval = lngTI
  14.         .OnTimer = "[Event Procedure]"
  15.     End With
  16. End Sub 
Errors Encountered
When the code is ran..the line
.Dirty= False gives a debug error
The error is Run-time error '2455'
You have entered an expression that has an invalid reference to the property Dirty

Also the txtSendDate value is updated but when i close the form and reopen it the txtSendDate value is blank..i.e. it is not saved once the form is closed

At this point, i have tried a lot of ways but i am totally clueless as to what is going wrong.Please help and sorry for incovenience caused

Jan 9 '12 #18
32,182 Expert Mod 16PB
It seems you haven't copied the code across very well. It is critical, in such situations, to use Copy / Paste to avoid such mistranslations.

If you look at lines #3 & #4 in your code and compare them to mine you'll see a big difference (in effect rather than characters). Line #4 should also be <= rather than <>. Your code, as it stands, ensures the code can never be executed. This also explains the extra line #9 that you have (which is incorrect).

As for the .Dirty problem, I admit that confuses me. It's been a few weeks since I looked at this so I'm not even sure I kept the earlier work (I probably did, but finding it is another matter). I'm pretty sure I tested it at the time though and it worked. Otherwise the DoCmd.SaveRecord() line would still be there (It was commented out). The txtSendDate value being updated is dependent on the .Dirty line working correctly, so no surprise there at this stage. I'm working in Access 2003. Which version are you working with?

I notice that you have changed my line :
Expand|Select|Wrap|Line Numbers
  1. .txtSendDate = DateAdd("d", 30, CDate(.txtSendDate))
to :
Expand|Select|Wrap|Line Numbers
  1. .txtSendDate = DateAdd("d", 30, (.txtSendDate))
Essentially removing the call to CDate(). This shouldn't have too much of an effect in itself, but the fact you made the change indicates something amiss with the data entered (I'm assuming the change wasn't a random idea).

PS. Tip: Always compile your code before testing it. It helps avoid wasting your time and energy.
Jan 9 '12 #19
Hi Neopa,

Yeah i just saw the chnages you highlighted, was testing and tweaking the code and didnt even realise the changes i made.
Currently, i am using Access 2007
I have corrected the code and ran it again but is still giving me the error about the Dirty property
I guess i need to go back to the the foundation/beginning and figure out how i went wrong

Thanks for all your help,
Really appreciate it
Jan 9 '12 #20
32,182 Expert Mod 16PB
As that's the only problem I would suggest checking the Context-Sensitive Help system for "SaveRecord". It may be that this will work in 2007. Alternatively, you may find there how best to save the active record in a form from there. That's the only piece of the puzzle that's missing ATM. Restarting from scratch seems to me to be throwing the baby out with the bath-water. An option, but not a good one.
Jan 9 '12 #21

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Mailer-Daemon | last post: by
reply views Thread by Mail Delivery System | last post: by
reply views Thread by murugesh82 | last post: by
reply views Thread by Mail Delivery System | last post: by
5 posts views Thread by Troels Arvin | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.