Re: Unsure why VBA thinks dates entered are greater than Now() - when they are not?



Thx for the explanation, Marshall.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


On Wed, 08 Aug 2007 13:29:12 -0500, Marshall Barton
<marshbarton@xxxxxxxxxx> wrote:

MLH wrote:

Seems that Tom van Stiphout hit it on the nose. Must-a-been
some kind-a-string comparison going on, rather than a date-to-date
comparison. I ran his suggested tests in the immediate window.
So I took banem2 up on his suggestion to encapsulate the textbox
reference inside CDate(). Apparently, that had an effect and seems
like the one I want.

Your comments re: Before vs After Update were well received too.
Thx.

After having made the 'fix', I found more places in my code were
greater-than / lesser-than comparisons may be returning questionable
results. So I'll likely take Tom van Stiphout up on his suggestion to
use DateDiff in some of these places. Although, I haven't tested and
am unsure what DateDiff(Forms!MyForm!MyControl,Now) will do if user
types 8/15/2007 in a textbox without surrounding it with #...#

I guess, in the OP, I was hoping someone might know how I could
inform A97 that a particular textbox on a form contained a date and
that any subsequent use of the value in there would be treated as if
it were a date. I mean, I can use datediff, yeah. But, looking at an
integer difference representing the number of days between two dates
and considering the sign of the value returned is more trouble than
asking "Hey, is Date1 > Date2?" Huh? Huh? That's quick & easy
whereas the former is labor-laden.


As others have said, when you enter something like 8/15/2007
into a text box, Access has to try to figure out what it
should do with the characters. The first clue Access uses
in its guessing process is to check the type of the field
bound to the text box. If it's a Date type, you might be
ok. If it's a Text field, then you will probably see your
problem.

OTOH, if the text box is not bound, then Access looks at the
text box's Format property to see if it provides any clues.
If the Format is the kind used for a date/time, then you are
probably ok. Any other kind of format, including none will
lead Access off in the wrong direction and your data might
be interpreted in some way that you don't like.

If you follow Lyle's advice, you can avoid the "might" and
"probably" involved when you let Access play its guessing
game.

.



Relevant Pages