Solved

Set Default Date in a table.

Posted on 2006-11-24
6
249 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

733 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