Solved

Set Default Date in a table.

Posted on 2006-11-24
6
247 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 50 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…

773 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