date function

L

lynn atkinson

Could someone remind me of the function to automatically enter todays date,
but not so it is updated everytime the database is accessed. ie I want a date
to be entered as today, but the database should keep that date.
Hope this makes sense!
 
N

Nikos Yannacopoulos

Lynn,

The function that returns th current date is simply Date(). In order to
achieve what you want, the simplest way is to put this function in the
Default Value property of the date field in the table. That way it will
default in (and keep) the current date whenever a new record is created in
any way (manually in the table or through a form, through an append query,
code or whatever), but allow you to change it if you want.

HTH,
Nikos

If your data entry is done manually through
 
L

lynn atkinson

That is what I have used, but the set up is this. I have a check box which is
ticked if a a course is cancelled. the date field control source is based on
this check box with an IIF statement as follows
=IIf([cancelled]=-1,Date(),"")

However, what is happening is that the current date is displaying in this
date field ie today all the cancelled courses were cancelled on 18/11/04,
according to the database. What I want is the field to store the date the
check box is ticked.

regards
 
D

Dan Artuso

Hi,
If you mean you want the default value to be todays date, then just use Date() in the
Default Value for that control. That way, the date is entered only in new records.
 
A

Allen Browne

Hi Lynn

Use the AfterUpdate event procedure of the Cancelled control to assign the
value to your date field.

This example assumes the date field is called CancelDate. If the box is
checked, it assigns the date, and if the box is unchecked, it clears the
date:

Private Sub Cancelled_AfterUpdate()
If Me.Cancelled.Value Then
Me.CancelDate = Date()
Else
Me.CancelDate = Null
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

lynn atkinson said:
That is what I have used, but the set up is this. I have a check box which
is
ticked if a a course is cancelled. the date field control source is based
on
this check box with an IIF statement as follows
=IIf([cancelled]=-1,Date(),"")

However, what is happening is that the current date is displaying in this
date field ie today all the cancelled courses were cancelled on 18/11/04,
according to the database. What I want is the field to store the date the
check box is ticked.

regards

Nikos Yannacopoulos said:
Lynn,

The function that returns th current date is simply Date(). In order to
achieve what you want, the simplest way is to put this function in the
Default Value property of the date field in the table. That way it will
default in (and keep) the current date whenever a new record is created
in
any way (manually in the table or through a form, through an append
query,
code or whatever), but allow you to change it if you want.

HTH,
Nikos

If your data entry is done manually through
 
Top