I have a database that has several different training topics each that a due at different intervals.
I have a date completed field [Date completed] and reoccurs every x months [recurrence] and then the next due date [due date].
How do I get my database to calculate and store the next due date? Please use (For dummies) explanation.
Date_Completed = Date Field Recurrence = TXT Field Due_Date = Date Field
Software/Hardware used:
Micorsoft Access 2007
ASKED:
November 16, 2010 5:35 PM
UPDATED:
November 18, 2010 12:25 AM
I still don’t understand where to put this code to update the field in the table
If you want to update the field for all the existing records, you would need to create a query with the UPDATE statement mentioned above.
If you want to update it automatically when new records are added, then you will need to modify the entry form to do the calculation when some event occurs.
Let us know how and when you want to do it, and we might be able to provide more help.
I am working on the database right now. Again, I am a very novice user. I am in the military and trying to track the training of some of my troops. I would like to input the information in my form and have it calculate the due date and store that information in the table. I will then create a query to give me a list of all people that are within 30 days of the due date so they can start working on the training. Thanks for your quick response. Please help.
You could use the AfterUpdate trigger.
In design mode (right click on the form and select ‘design View’), click on the [Recurrence] field and in the Property Sheet select the ‘event’ tab, then click on the “After Update” event and click on the “…” button to the right, and select “Code Builder”.
Write this code inside the Recurrence_AfterUpdate procedure created:
[Due Date] = DateAdd("m", [Recurrence], [Date Completed])Save your work.
This will calculate the due date every time you modify the Recurrence field in the form.
To make sure the calculation is performed only when valid data exists in both fields (date completed and recurrence) you can add some validations:
If [Date Completed] <> "" And [Recurrence] <> "" Then [Due Date] = DateAdd("m", [Recurrence], [Date Completed]) End IfYou might want to add this same code to the AfterUpdate event of the ‘date completed’ field, so the due date is recalculated when any of these two fields is modified.
sounds like we are on the right track, when I put the code [Due Date] = DateAdd(”m”, [Recurrence], [Date Completed]) in the “After Update” code builder, it gives me a run time error. Any thoughts?. Also just so you know there is nothing else in the database that I am trying this on. I have a test database with only those three fields in the table. The (Date Completed) is a date/time field, the (Recurrence) is a Number field and the (Due Date) is a date/time field. Not sure if this matters.
****** I just put your code in a query and it works. But I want it to work in the Form… We are getting close. Thank you for your help, I am very excited about getting this done.
OK I got it. *******
I renamed the tables without any spaces i.e. Due_Date instead of Due Date and it worked. I don’t know why this is, but it worked. Thank you so much.
Can you post the complete error message ?
Also, when does the error occur ?
Great !
Glad it worked.
(Disregard my last comment, I didn’t see you last post until I submitted mine).