Dates & initial values

  • Thread starter Thread starter Cheswyck
  • Start date Start date
C

Cheswyck

I have a form to enter activity data. the date is usually
in the past. I tried leaving the field with no initial
value and I get an error saying invalid use of null as
soonas I enter the first digit. Then I used today's date
and it worked ok when I entered the correct date. Now I
want to change the initial date to be today if it is the
first entry or the previous record's date if the second
record is being entered. what instruction can I use? can
it be some kind of iif(empty(controlDate),today(),previous
record's date)?? How do I refer to the previous records
date entry? And should I put it in the default property?
 
Cheswyck said:
I have a form to enter activity data. the date is usually
in the past. I tried leaving the field with no initial
value and I get an error saying invalid use of null as
soonas I enter the first digit. Then I used today's date
and it worked ok when I entered the correct date. Now I
want to change the initial date to be today if it is the
first entry or the previous record's date if the second
record is being entered. what instruction can I use? can
it be some kind of iif(empty(controlDate),today(),previous
record's date)?? How do I refer to the previous records
date entry? And should I put it in the default property?


Depends on what you mean by "previous".

If you mean the previously entered record in the current
form "session", then use the date text box's AfterUpdate
event to set the text box's DefaultValue property.

Me.txtDate.DefaultValue = Me.txtDate

You can set the text box's DefaultValue property in design
view to =Date() so the first new record after the form is
opened is today's date.
 
I added the your code and the first's transactions date
defaulted to today but the next transaction's date entry
changed to 12/30/1899.
The 1st entry date is defaulted to today's date. I added
a 'Me.timDate.DefaultValue = Me.timDate' instruction to
the after update property. As soon as I exit the field, I
can see the next transaction's entry date change to
12/30/1899. So I tried it on the on-exit property and got
the same results.
timDate is the name of the field in the table and the name
of the control field in the form.
 
Cheswyck said:
I added the your code and the first's transactions date
defaulted to today but the next transaction's date entry
changed to 12/30/1899.
The 1st entry date is defaulted to today's date. I added
a 'Me.timDate.DefaultValue = Me.timDate' instruction to
the after update property. As soon as I exit the field, I
can see the next transaction's entry date change to
12/30/1899. So I tried it on the on-exit property and got
the same results.
timDate is the name of the field in the table and the name
of the control field in the form.


That's the date you get when the value is zero. I don't
know how you could could get that, maybe a locale setting??

Try this and see if it works better:

Me.timDate.DefaultValue=Format(Me.timDate,"\#m\/d\/yyyy\#")
 
Back
Top