Hi,
I have a question about my code posted below. For some reason, if
txtCurrentWeek.Value = 5 and txtTotalWeek.Value = 21, the msgbox will be
displayed, even though it shouldn't. I belive it has to do with the value
not being read as an integer or the length of the value (I assumed this
because if I set 'current' = 1 or = 2 and 'total' = 21, I get no error
message. Do I have to declare these .values as integers or to have a
specific length? If so how do I do that?
If txtCurrentWeek.Value > txtTotalWeek.Value Then
MsgBox "Current project week cannot exceed the total number of project
weeks.", vbOKOnly, "Error"
Exit Sub
End If
Thanks.
Jay Freedman - 10 Nov 2006 21:34 GMT
The .Value is a string, so the greater-than operator is doing
character-by-character string comparison. Change the expression to
If Val(txtCurrentWeek.Value) > Val(txtTotalWeek.Value) Then
to compare the numeric values.
Instead of the Val() function, you can use the CInt() function. The only
practical difference is that if myString contains something other than
digits, CInt(myString) will throw a type-mismatch error but Val(myString)
will return 0. Sometimes one or the other is preferable.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
> Hi,
> I have a question about my code posted below. For some reason, if
[quoted text clipped - 12 lines]
>
> Thanks.