DatePart in default value

L

Lambi000

I have a form that uses the date function Date() to automatically throw the
current date in the field. I do that by using Date() in the default
property. I would like the week number to do the same, but it won't work in
the default property.

DatePart("ww",[Date]) is the format I'm using, date being the form field in
which the current date is.

If I just give the field value of DatePart("ww",[Date]) I see the week
number, but I'm trying to save it in the database with the date and not just
show the number.

What am I doing wrong? Do I have do a VB module or can I place the function
somewhere in the properties?

Thanks
 
K

Klatuu

There are a few issues here. First, in this line, you have Date in brackets.
If this means you have a field named Date, then you need to change it. Date
is a reserved word and using it as a name will cause problems.
Second, you should not store the week number in your table. You have the
date captured in a field, so you have what you need to calculate the week
when you display the record. Storing calculated values violates good
database normalization.
For the week field, I would suggest you use the Control Source property of
the control in which you want to display the week number using this:

=Format([Date], "ww")

And again, change the name of the field in the table and the control on the
form to something other than Date.

DatePart("ww",[Date])
 
L

Lambi000

Ok, I did what you said and it's working. I used the DatePart() function in
the Source data for the form and, for the inevitable spreadsheet I give my
boss, I calculated the week in a query.

Thanks!

Klatuu said:
There are a few issues here. First, in this line, you have Date in brackets.
If this means you have a field named Date, then you need to change it. Date
is a reserved word and using it as a name will cause problems.
Second, you should not store the week number in your table. You have the
date captured in a field, so you have what you need to calculate the week
when you display the record. Storing calculated values violates good
database normalization.
For the week field, I would suggest you use the Control Source property of
the control in which you want to display the week number using this:

=Format([Date], "ww")

And again, change the name of the field in the table and the control on the
form to something other than Date.

DatePart("ww",[Date])
--
Dave Hargis, Microsoft Access MVP


Lambi000 said:
I have a form that uses the date function Date() to automatically throw the
current date in the field. I do that by using Date() in the default
property. I would like the week number to do the same, but it won't work in
the default property.

DatePart("ww",[Date]) is the format I'm using, date being the form field in
which the current date is.

If I just give the field value of DatePart("ww",[Date]) I see the week
number, but I'm trying to save it in the database with the date and not just
show the number.

What am I doing wrong? Do I have do a VB module or can I place the function
somewhere in the properties?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top