Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field name is "date" now I can't use "Date()" Function 2

Status
Not open for further replies.

dontay

Programmer
Jan 22, 2003
49
US
Hi All,
In one of my first Access Apps I named a date field "date".
Now when I try to use the "Date()" function, instead of producing the current date it produces what ever date that is in the "date" field. In other words when I try to use the "Date()" function it thinks I'm referencing the "date" field, when all I want is the current date....
How can I use the "Date()" function in a sub procedure that will give me the current date?
Thanks
Don
 
I would rename the field in the table and be done with it. I suppose you could prefix the Date() function with the library name and then there should be no confusion. The date function is in the vba library.

vba.Date()
 
Hi

You might get away with [Date]

but either way put it down to experience this is a valuable lesson use a naming convention for all objects, column names etc eg datDate would have saved you the heartache

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Dontay,

I always use int(now()) instead of Date() - it does exactly the same job, but is for some reason more reliable.

Iain :)
 
Hi dontay,

As already said, it's bad practice to use reserved words as field names. However, you should be able to work with them, and I don't understand what you are doing.

This is the Access Modules (VBA) Forum and I can't reproduce your problem in VBA from the little information given. I CAN imagine how it might happen in, say, the Query builder. Could you give a bit more detail of what you are entering where.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi all,
Thanks everyone for the help. I have yet to have a question that can't be answered on this site. This is great!
Tony,
The problem is on an access form where the data source comes from a table that has a field name "date". If I try to update another txtbox on that form with the "date()" function, it updates it with the date that is in the date field, not the current date.
cmmrfrds (Programmer)suggestion of "VBA.date()" works fine in the sub procedure but I couldn't get it to work in the data default property.
Iain's suggestion of int(now()) works fine in both cases.
Thank you Thank you
Don
 
Hi Don,

Glad you're all sorted, but I don't have any problems with this and suspect it's just down to not entering it correctly.

If I enter [blue]Date[/blue] as the Control Source, I get the value of the Date Field on the current record. If I enter [blue]=Date()[/blue] (which I believe is the correct way to enter a function) I get the current date.

For a Default Value, if I enter [blue]Date[/blue], quotes get wrapped around it; if I enter [blue][Date][/blue] or [blue]=[Date][/blue] I get the Date Field, and if I enter [blue]=Date()[/blue] I get the current date.

Some of the confusion may be caused by Help giving the syntax simply as Date and by Access accepting this slightly non-standard syntax without parentheses for some common functions in some circumstances (CurrentDb is another example).

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top