Arvin and Dale,
Thank you for your input.
First, to answer your question Dale. I was trying to use code because I am
still a relatively ignorant new user of Access!!
Based on your advice I scoured all table fields with a data type of
Date/Time to ensure that there are no default values except Null in cases
where Date() is used as the default value the properties of relevant form
controls.
I have also searched all the coding for the project to make sure that I have
not inadvertently defined 'Date' as a variable.
I now seem to be getting today's date to default on forms as required.
However, I still have a need to use Date() within my code. For example, a
form that is used to enter search parameters includes a 'Clear Fields'
command button that (I would think) needs the following code:
Me.txtDteTo = Date() (to default today's date back into the control
after user editing)
However, the VB editor changes the code to read:
Me.txtDteTo = Date
When this code is run today's date defaults to the field.
I have also created a new database, created a form with an unbound control
and then attempted to code Me.Text0 = Date() and the parentesises disappear!!
I am getting the functional outcomes I require but I am so confused over why
Date() loses its parenthesises within VB code while Now() does not!!
Regards,
Terry
Dale Fye said:
Not sure why you are doing this in code. As Arvin states, you can do it in
the tables properties, or if you set it the default value to NULL in the
Table properties, then you can set the controls default value to =Date() in
design view.
Either of these methods should ensure that a new record will contain todays
date, without resorting to code.
--
HTH
Dale
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
TESA0_4 said:
Hi,
I want to default today's date to a bound field when a form opens to create
a new record. I 'thought' that the code should read as follows:
Forms![frmRiskAssActPlan]!DueBy.DefaultValue = Date()
However, as soon as the focus of the cursor moves from the line, the VBA
editor deletes the parenthesis so the line reads:
Forms![frmRiskAssActPlan]!DueBy.DefaultValue = Date
When I run the code the form opens with 31/12/1899 as the defaulted date.
Can someone please tell me what I am doing wrong??
Regards,
Tesa