Ken Ismert
KIsmert at TexasSystems.com
Mon Mar 14 13:23:59 CST 2005
Sander,
On this line:
If Not dtmNewBusinessDate = "00:00:00" Then
A date is never equal to a string; they are incompatible data types. Yet the
code does work because the VBA interpreter attempts an implicit conversion
of the string into a date, in order to compare apples to apples.
The problem is, you can put any string value in this comparison. While:
If Not dtmNewBusinessDate = "hello" Then
compiles correctly, it will give a type mismatch error at runtime. But, this
line:
If Not dtmNewBusinessDate = #hello# Then
will give you a syntax error when you compile.
Implicit conversions are tricky because they rely on (largely undocumented)
rules for variable coercion, which may not always work the way you expect.
They also assume the reader understands that what you are writing is
equivalent to:
If Not dtmNewBusinessDate = CDate("00:00:00") Then
Rather, be explicit:
If Not dtmNewBusinessDate = #00:00:00# Then
Or, better yet:
Public Const GDT_Day0 As Date = 0
...
If Not dtmNewBusinessDate = GDT_Day0 Then
-Ken
Reference:
See "Variant Data Type" section in:
http://support.microsoft.com/kb/q110264/
-Ken