[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set Default Date in a table.

Posted on 2006-11-24
6
Medium Priority
?
255 Views
Last Modified: 2008-03-10
I am making a Database where I want to set the default date in the "DueDateS1" field to be 30 days from the "Date" field.
"Date" = Entered by data entry in table or Form
"DueDateS1" = To automatically calculate off of the "Date" entered.

I tried to use the DateAdd("d", +30, <<date>>) function and I am not sure what goes in the <<date>>.  I've tried using both "Date" and "DueDateS1"

I am pretty new to writing this type of code so any help would greatly appreciated.
0
Comment
Question by:rhedges
6 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 200 total points
ID: 18011178
Hi rhedges,

You cannot do this in a table design.
If you use a form then you can do what you require although it requires a ine of code to do so as below.

It is a bad idea to call a field Date because Date is a reserved word in Access.  Use a more descriptive fieldname.

The code you want goes in the Afterupdate event procedure of the first date field (which I shall call MyDate).

me.DueDateS1 = me.Mydate + 30

Note that any time the user changes the value in MyDate the DueDateS1 will be recalculated.

Pete
0
 
LVL 1

Expert Comment

by:Metroid
ID: 18011181
Hey rhedges,

To do this all you need to do is add the proper interval and field for the date (ie. DateAdd("d",30,[table field that contains date]).

Hope this helps.
0
 
LVL 1

Expert Comment

by:Metroid
ID: 18011186
RHEDGES,

Pete is correct in that you can't do this in a page design.  I would suggest you do this in a query. I would test it out by just doing a simple query using the date you want to modify.  Basically, DateAdd("d",30,[field with date]).
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:p912s
ID: 18011660
As mentioned above you should change the name of your date field to MyDate or EntryDate or whatever makes sense...

If the date field is an EntryDate so it is equal to today where you can set the default in the field properties to =Date() then you could also set the DueDate the same way by making it's default value =Date()+30

Otherwise depending on how you're entering data in the table it could be done in a query on a form or ....


Hope that helps.

Scot
0
 
LVL 1

Expert Comment

by:Metroid
ID: 18011845
RHEDGES,

I read over your post again and since you are using a form to enter data just create a field next to the date entered field and use the formula that you are using (with just the slight modications that I gave you) and plug it into that field or use the one Pete provided (if you need assistance with that, then let us know).

Pete is correct that you can't do this within table design but either methods should work.

M
0
 
LVL 44

Expert Comment

by:GRayL
ID: 18016044
rhedges:  I case you didn't get it, you cannot enter an user defined function as a default.  Date(), Year(Date()), etc. are all instrinsic to Access and will pass, anything "you" the "user" defines will not.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question