473,836 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automated Mail Delivery Time Using Table Data

elak6
21 New Member
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
Dec 5 '11
20 3851
NeoPa
32,584 Recognized Expert Moderator MVP
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
NeoPa
32,584 Recognized Expert Moderator MVP
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
  3.  
  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
  16.  
  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
elak6
21 New Member
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,
elak6
Dec 12 '11 #13
NeoPa
32,584 Recognized Expert Moderator MVP
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
NeoPa
32,584 Recognized Expert Moderator MVP
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
  3.  
  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
elak6
21 New Member
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
NeoPa
32,584 Recognized Expert Moderator MVP
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
elak6
21 New Member
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
  3.  
  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

Thanks
Jan 9 '12 #18
NeoPa
32,584 Recognized Expert Moderator MVP
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.SaveRecor d() 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
elak6
21 New Member
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

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

Similar topics

0
517
by: Mailer-Daemon | last post by:
Dear Internet Email User, this is an automated mail delivery notification, because your email has not been delivered the usual way. Your mail was not deliverd for the following reason: Your mail contained an attachment with the filename extension
0
1296
by: Mail Delivery System | last post by:
This message was created automatically by mail delivery software. A message you sent could not be delivered to the following recipients: ngr@cotswold.demon.co.uk RSET 250 ok MAIL FROM:<python-list@python.org> 250 sender is python.org!python-list RCPT TO:<ngr@cotswold.demon.co.uk>
0
1339
by: Vexira | last post by:
* * * * * * * * * * * * * * * Vexira ALERT * * * * * * * * * * * * * * * This version of Vexira MailArmor is licensed and full featured. Vexira has detected the following in a mail from your address: Worm/NetSky.P.ExplWorm/NetSky.P, Worm/NetSky.P.Expl The mail was not delivered. Your computer may be infected with a virus! Please visit
9
4331
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra instance of the Access application is opened and remains open at the end. Sometimes it remains open
0
1251
by: murugesh82 | last post by:
Hi friends, I am doing project on java n j2ee. i am facing problem on sending automated mail to the customers when they registed? Plz how to do it.
3
2105
by: Richard Gilmore | last post by:
within my database I have a login form with a forgot password button when the button is clicked you are prompted to enter your email in frmforgotpassword this value is used for the parameters of the qryforgotpassword I then want to perform a mail merge to my precreated document "password merge" So far using code I have managed to get the mail merge to work but it always opens up another instance of my database and asks me for the for a value...
0
3813
by: Mail Delivery System | last post by:
--foo-mani-padme-hum-2391-1-1176705911 Content-Type: text/plain This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: giles@localhost SMTP error: 550 X-Spam_score: 9.0
1
1672
by: steve | last post by:
I'm fairly new to Access and trying to figure out how to execute a particulary query. For example I have 2 tables named TEST and TEST1. TEST has a column labeled LETTERS with values A - Z. I want to execute the query SELECT ALL FROM TEST1 WHERE LETTERS = TEST.LETTERS. I want to reexecute the query for each record in the TEST1 table. Can I do this directly in a query or do I have to write a module. Any help would be appreciated. Steve
5
6569
by: Troels Arvin | last post by:
Hello, Every so often, I'm asked to help people recover data from tables that were either dropped or where to much data was DELETEed. The complications related to restoring data are a problem. The SAS users are laughing because they can (to a certain extend) easily go back to an earlier SAS table by simply starting dsm. Of course, a flat file table is different than a relational table; but still, the trouble related to restoring DB2...
0
1220
by: Baspad | last post by:
Hi... I want this topic is very urgent. can you help me.... How do access the delivery confirmation using CDONTS.NEWMAIL....
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9664
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10832
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10584
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.