Solved

Set Default Date in a table.

Posted on 2006-11-24
6
245 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now