Default Date() and Time() quit working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that had the control source set to the table. Date and Time
text boxes default values were set on the form to Date() and Time()
respectively. This worked just fine. I had a problem with the record order on
the form and had to change the form's control source to a query based off the
table so that I could get the order I wanted. From that point on, default
Date() and Time() quit working. I have tried everything I can think of, and
have band-aided the problem by creating a button that runs code on click as
follows:

Private Sub AutoDate_Click:
Me.Date = VBADate
Me.Time = VBATime
Exit Sub

This works but the user has to hit the button to populate the fields. I'd
much rather figure out why it won't work on default like it used to.
I have even tried to make the fields default on the table. This makes the
new record show the date and time in the query, but it still won't show on
the form.
I'm pulling my hair out over something that I know should be simple. I'd
appreciate any help I could get.
 
Default values : =Date() & =Time() Should Work (you can even use them at
Table Level)
You Can However put your code in the Form BeforeInsert Event to automate it
in another way

Pieter
 
I have a form that had the control source set to the table. Date and Time
text boxes default values were set on the form to Date() and Time()
respectively. This worked just fine. I had a problem with the record order on
the form and had to change the form's control source to a query based off the
table so that I could get the order I wanted. From that point on, default
Date() and Time() quit working. I have tried everything I can think of, and
have band-aided the problem by creating a button that runs code on click as
follows:

Private Sub AutoDate_Click:
Me.Date = VBADate
Me.Time = VBATime
Exit Sub

This works but the user has to hit the button to populate the fields. I'd
much rather figure out why it won't work on default like it used to.
I have even tried to make the fields default on the table. This makes the
new record show the date and time in the query, but it still won't show on
the form.
I'm pulling my hair out over something that I know should be simple. I'd
appreciate any help I could get.

What are VBADate and VBATime?
Error's out on my computer.

Me![DateField] = Date
Me![TimeField] = Time
should work.

Date, as well as Time, are reserved Access/VBA/Jet words and should
not be used as a field name.
For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

Also, check your References.
 
I was reading another post about reserved words where someone suggested using
VBADate in code instead of just Date. That works for me, but I don't want to
have to click the button to get the default values to work. I have tried
default value of the form and the table to =Date() and it won't error, but
won't work either. In VBA I tried Me.Date = Date but it won't work without
VBADate. Maybe its just that my date and time columns are named simply date
and time. I will try renaming them, although I don't get why they would work
before and just stop.

fredg said:
I have a form that had the control source set to the table. Date and Time
text boxes default values were set on the form to Date() and Time()
respectively. This worked just fine. I had a problem with the record order on
the form and had to change the form's control source to a query based off the
table so that I could get the order I wanted. From that point on, default
Date() and Time() quit working. I have tried everything I can think of, and
have band-aided the problem by creating a button that runs code on click as
follows:

Private Sub AutoDate_Click:
Me.Date = VBADate
Me.Time = VBATime
Exit Sub

This works but the user has to hit the button to populate the fields. I'd
much rather figure out why it won't work on default like it used to.
I have even tried to make the fields default on the table. This makes the
new record show the date and time in the query, but it still won't show on
the form.
I'm pulling my hair out over something that I know should be simple. I'd
appreciate any help I could get.

What are VBADate and VBATime?
Error's out on my computer.

Me![DateField] = Date
Me![TimeField] = Time
should work.

Date, as well as Time, are reserved Access/VBA/Jet words and should
not be used as a field name.
For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

Also, check your References.
 
Back
Top