Diff Between Date and Date()

  • Thread starter Thread starter Mike Thomas
  • Start date Start date
M

Mike Thomas

When to use Date and when to used Date() has bothered me for some time.

In a VB module, I have this snippet:

strSQL = "UPDATE part_cost SET quoteend = Format(date-1,'yyyymmdd')
Where......."

It worked fine fior a couple of days, then I got an "Expected Parameters..."
error. I changed the line to :

strSQL = "UPDATE part_cost SET quoteend = Format(date()-1,'yyyymmdd')
Where......."

Now it works.

Where is date, and where is date() used?

Many thanks
Mike Thomas
 
In the context of VBA code, use the Date statement.
If you use the Date() function, Access automatically removes the brackets.

In other contexts (such as in the Criteria of a query or in the Control
Source of a text box), you cannot use VBA statements, but you can use
function calls that return a value.
 
Where is date, and where is date() used?

Date() is used whenever it is necessary to unambigously tell Access
that you mean the built-in function of that name. In a SQL query, just
the bare word Date could refer to a fieldname, a parameter, or the
function; the parentheses clearly indicate that you mean to call a VBA
Function.

Within VBA code, the compiler can usually unambigously determine what
you mean, so it strips off the parentheses if you include them. I've
gotten in the habit of just typing Date() whenever I want to call the
Date function, and let Access throw away the parens if it wants to.
 
Thanks again, Allen


Allen Browne said:
In the context of VBA code, use the Date statement.
If you use the Date() function, Access automatically removes the brackets.

In other contexts (such as in the Criteria of a query or in the Control
Source of a text box), you cannot use VBA statements, but you can use
function calls that return a value.
 
Many thanks again, John
John Vinson said:
Date() is used whenever it is necessary to unambigously tell Access
that you mean the built-in function of that name. In a SQL query, just
the bare word Date could refer to a fieldname, a parameter, or the
function; the parentheses clearly indicate that you mean to call a VBA
Function.

Within VBA code, the compiler can usually unambigously determine what
you mean, so it strips off the parentheses if you include them. I've
gotten in the habit of just typing Date() whenever I want to call the
Date function, and let Access throw away the parens if it wants to.
 
Back
Top