Date() vs. Now() ??

D

David Peterson

What are the rules for using when to use Date() and when to use Now()?

Sometimes I get errors when I use Date and they go away when I change it to
Now
 
F

Fredg

David,
If the Field is a Date/Time datatype,
store Date() in the field whenever you will only require the Date value.
Store Now() whenever you require a Date and Time value.

If you are getting errors, it would be useful to know under
what conditions this occurs.
Best I can guess without more information, is that you are
searching for records using Date() when the field is storing the
Date and Time or using Now() when the field is only storing the Date.
That shouldn't cause an Access error, but it will cause incorrect
(or not enough records) to be returned.
 
D

Douglas J. Steele

Depending on what David means by "errors" with Date, it could be a
References problem. I don't understand it myself, since I think both Date
and Now come from the same VBA library, but it seems that Now doesn't
usually suffer from the same problems as Date in this regard.
 
D

David Peterson

M y errors are occurring when I compile the code.
When I type Date() in VBA code the on-screen word changes to Date {the ()
disappears}.
When I compile the code I get unrecognized command or keyword in the line
where date is.
 
J

John Vinson

M y errors are occurring when I compile the code.
When I type Date() in VBA code the on-screen word changes to Date {the ()
disappears}.

This is normal behavior. Functions with no arguments don't need the ()
in VBA (although they do in SQL... Microsoft is NEVER consistant!)
When I compile the code I get unrecognized command or keyword in the line
where date is.

Perhaps you could post your code, with the actual error message. It's
a bit hard to debug at this distance!

Howver, it could be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.
 

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