David said:
I would change that to:
DoCmd.OpenForm "NorthWeldDailyfrm", , , "txtDate =#" & Date() & "#"
With my settings, that would barf with RT 3075, cause the *string*
passed to the evaluation services, would look like this
txtDate =#26.09.2007#
which Jet isn't very happy with.
With UK settings, it would cause anomalities where day < 13
When we're using dynamic SQL, as for instance in the WhereCondition
of some of the DoCmd methods, it's important that what we pass to
the evaluation services, aren't dates, numbers, text etc. It's a
*string*.
This string will contain the names of the fields, some operators
and literals representing the values we wish to pass. If the
literals are in the correct format, have the correct delimiters,
etc, Jet will understand, evaluate (and implicitly coerce?)
correctly, and perform. Else, the result is anomalities or RT 3075.
Evaluation services can happily deal with some functions, as for
instance the Date() function, so the *string*
"txtDate = Date()"
as WhereCondition is quite OK, as the OP suggests.
If we use the format function on a valid date when concatenating
dynamic SQL, the date is explicitly converted to a string literal
using the format specified (one would probably use either ISO 8601
or mm\/dd\/yyyy), which will make Jet able to understand the
*string* when passed, regardless of locale, because the string
literal concatenated into the SQL string, is in a unambiguous
format.
Note also that some regional settings specify comma as decimal
separator, which makes some tweaking necessary also for numbers
with decimals, when concatenating dynamic SQL. One might for
instance use the Str() function on such numbers.
You can pass "dates" to dynamic SQL through other means, too, for
instance by using Long or Double *) (here, in the latter case,
relying on a bit implicit coersion).
Say
CurrentDB.Execute "UPDATE myTable SET myDate = " & Str(CDbl(Now)) & _
" WHERE myID = 42", dbFailOnError
DoCmd.OpenForm "SomeForm", , , "myDate =" & Clng(Date)
But again, as far as I've understood, what Jet (or the expression
services) receives, evaluates and finally performs, is not dates,
text, or numbers, but a *string* with literals representing the
values we pass. Here, the first string will get a properly
formatted decimal number (i e, the Str function replaces the comma
I would get as decimalseparator with my settings, with dot), the
latter coercion is implicit, but I usually allow that for long.
Thise concatenated strings are then passed to Jet for evaluation
and execution.
*) 0 date of SQL server and Jet is off by two days, which means the
above will provide anomalities when executed on ADO OLE DB vs ODBC
with SQL server
SELECT Cast(0 As DateTime) -> 01/01/1900
Debug.Print Format(0, "mm\/dd\/yyyy") -> 12/30/1899
)