By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,474 Members | 1,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,474 IT Pros & Developers. It's quick & easy.

IF Less Than (<) not working in VB Code - Access 2000

P: n/a
Hello'

I am attempting to provide validation for a field on a form through a
command.
(the validation is only part of the command). The field is a text box
formatted as a fixed number...

Basically I want the resulting value to only be allowed to be between
2 & 8.

The code works fine for the greater than (>) but for some reason does
not work for less than(<) ??
abbreviated code snippet:

If Me.Field "2" And Me.Field < "8" Then
Me.cmdSave.Visible = True
MsgBox ("Good")
Else
MsgBox ("Bad")
If Me.cmdSave.Visible = True Then
Me.cmdSave.Visible = False
End If
End If

I even went as far as to leave out the AND portion of the statement &
only put in the 1 criteria (less than 8) & vice versa. Also used the
(.Value) qualifier for the field.

The greater than 2 criteria works everytime (whether after the less
than AND) portion of the line or before it, or on it's own with no AND
statement.

But the less than # will NOT work???

Any ideas why?
Oct 3 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ry***********@gmail.com wrote:
Hello'

I am attempting to provide validation for a field on a form through a
command.
(the validation is only part of the command). The field is a text box
formatted as a fixed number...

Basically I want the resulting value to only be allowed to be between
2 & 8.

The code works fine for the greater than (>) but for some reason does
not work for less than(<) ??
abbreviated code snippet:

If Me.Field "2" And Me.Field < "8" Then
Me.cmdSave.Visible = True
MsgBox ("Good")
Else
MsgBox ("Bad")
If Me.cmdSave.Visible = True Then
Me.cmdSave.Visible = False
End If
End If

I even went as far as to leave out the AND portion of the statement &
only put in the 1 criteria (less than 8) & vice versa. Also used the
(.Value) qualifier for the field.

The greater than 2 criteria works everytime (whether after the less
than AND) portion of the line or before it, or on it's own with no AND
statement.

But the less than # will NOT work???

Any ideas why?
Hmmm...do you only permit numbers from 3 to 7? If not, maybe use >= and <=.
Oct 3 '08 #2

P: n/a
Hmmm...do you only permit numbers from 3 to 7? *If not, maybe use >= and <=.
With or without the (=)'s I still get the same issue.

If the field ends up being less than (<) the lower value then the code
works fine...i.e Error message.
If the field ends up being greater (>) the higher value then the code
does not work... i.e. NO error message.

It's like Access is ignoring the greater than symbol???

Oct 3 '08 #3

P: n/a
sry... the Less than < symbol is being ignored by access...
Oct 3 '08 #4

P: n/a

"ry***********@gmail.com" <Ry***********@gmail.comwrote in message
news:d4**********************************@i76g2000 hsf.googlegroups.com...
Hello'

I am attempting to provide validation for a field on a form through a
command.
(the validation is only part of the command). The field is a text box
formatted as a fixed number...

Basically I want the resulting value to only be allowed to be between
2 & 8.

The code works fine for the greater than (>) but for some reason does
not work for less than(<) ??
abbreviated code snippet:

If Me.Field "2" And Me.Field < "8" Then
Me.cmdSave.Visible = True
MsgBox ("Good")
Else
MsgBox ("Bad")
If Me.cmdSave.Visible = True Then
Me.cmdSave.Visible = False
End If
End If

I even went as far as to leave out the AND portion of the statement &
only put in the 1 criteria (less than 8) & vice versa. Also used the
(.Value) qualifier for the field.

The greater than 2 criteria works everytime (whether after the less
than AND) portion of the line or before it, or on it's own with no AND
statement.

But the less than # will NOT work???

Any ideas why?
Can the value of Me.Field be greater then 9? A text compare of "10" < "8"
is true.

Try If cint(Me![Field]) 2 And cint(Me![Field]) < 8 Then

Oct 3 '08 #5

P: n/a
On Oct 3, 2:32*pm, "paii, Ron" <n...@no.comwrote:
"ryan.paque...@gmail.com" <Ryan.Paque...@gmail.comwrote in message

news:d4**********************************@i76g2000 hsf.googlegroups.com...


Hello'
I am attempting to provide validation for a field on a form through a
command.
(the validation is only part of the command). The field is a text box
formatted as a fixed number...
Basically I want the resulting value to only be allowed to be between
2 & 8.
The code works fine for the greater than (>) but for some reason does
not work for less than(<) ??
abbreviated code snippet:
* * If Me.Field "2" And Me.Field < "8" Then
* * * * * *Me.cmdSave.Visible = True
* * * * * *MsgBox ("Good")
* * * Else
* * * * * MsgBox ("Bad")
* * * * * * * * If Me.cmdSave.Visible = True Then
* * * * * * * * * * Me.cmdSave.Visible = False
* * * * * * * * End If
* * End If
I even went as far as to leave out the AND portion of the statement &
only put in the 1 criteria (less than 8) & vice versa. Also used the
(.Value) qualifier for the field.
The greater than 2 criteria works everytime (whether after the less
than AND) portion of the line or before it, or on it's own with no AND
statement.
But the less than # will NOT work???
Any ideas why?

Can the value of Me.Field be greater then 9? A text compare of *"10" < "8"
is true.

Try * If cint(Me![Field]) 2 And cint(Me![Field]) < 8 Then- Hide quoted text -

- Show quoted text -
You are the Man Ron!!!
That works!
So when an integer is in text field & I want to validate it based on
the Integer value, then I need to use the Cint function.
I got it committed to memory now! thank goodness for google groups...
Oct 3 '08 #6

P: n/a
"ry***********@gmail.com" <Ry***********@gmail.comwrote in message
news:b0**********************************@t54g2000 hsg.googlegroups.com...
On Oct 3, 2:32 pm, "paii, Ron" <n...@no.comwrote:
"ryan.paque...@gmail.com" <Ryan.Paque...@gmail.comwrote in message

news:d4**********************************@i76g2000 hsf.googlegroups.com...
>So when an integer is in text field & I want to validate it based on
the Integer value, then I need to use the Cint function.
I got it committed to memory now! thank goodness for google groups...

No, you don't have to. Your problem is:
If Me.Field "2" And Me.Field < "8" Then

You are using strings for "2", you should use

If Me.Field 2 And Me.Field < 8 Then
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com


Oct 4 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.