Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / April 2005

Tip: Looking for answers? Try searching our database.

Default Year in Date field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 14 Apr 2005 19:50 GMT
How do I set-up a DD/MM/YY date field so that I can put a default value in
for the Year ?





Paul Overway - 14 Apr 2005 19:46 GMT
Try

=DateSerial(Year(Date()),1,1)

Signature

Paul Overway
Logico Solutions
http://www.logico-solutions.com

> How do I set-up a DD/MM/YY date field so that I can put a default value in
> for the Year ?
Tim Ferguson - 14 Apr 2005 20:18 GMT
> How do I set-up a DD/MM/YY date field so that I can put a default
> value in for the Year ?
>  

I'm afraid you are in the hands of Windows itself. If you type into any
standard control in Windows something like "25/12" it will be converted
into  a date in the current year.

You will have to do some jiggery-pokery with the Text property but I have
a feeling that a control bound to a DateTime value will be coerced before
even the BeforeUpdate event has fired.

An alternative would be to pre-load the control with a suitable starting
date using the DefaultValue, so if it started out with 01/01/1999 the
user would only have to edit the first two parts.

Hope that helps

Tim F


Jamie Collins - 15 Apr 2005 12:58 GMT
> How do I set-up a DD/MM/YY date field so that I can put a default value in
> for the Year ?

The most relevant data type would be DATETIME, so the format would be
more like yyyy-mm-dd- hh:mm:ss (although I've heard said it's a
FLOAT/Double under the covers). You can ignore the time element and
hope/trust no one will put time elements in the database but a better
approach is to code appropriately using date functions: DATADD,
DATEDIFF, etc. If you store your date values as TEXT you will have to
do a lot more work.

A DEFAULT only takes affect when a row is first INSERTed. You will need
to choose the dd-mm element for your default value (TEXT data types
aside). You could use a CHECK constraint to enforce a year, unlike a
DEFAULT, a CHECK additionally bites on UPDATE.

Here's a bit of DDL I use often:

 ALTER TABLE MyTable ADD effective_date DATETIME DEFAULT NOW() NOT
NULL;

And another:

 ALTER TABLE MyTable ADD CONSTRAINT always_current CHECK
(effective_date = NOW());

Jamie.

--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.