Syntax for Logical Operators to Limit Input?

D

DCSwearingen

Good Morning,
I am creating a data entry form and have followed the tutorials written
by Peter Aitken in MSDN . He shows how to limit entry to numerical
values and that is very clear. I am trying to allow the user to enter
a percent such as 21.2%.

I just can't seem to find the right syntax . I can limit to the
decimal point or to the percent sign with a single statement. Or I can
limit to the numerical range of 1 through 9, but I can't seem to do all
three with one statement.

Here is the last statement I tried:

Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _
As MSForms.ReturnInteger)

If KeyAscii <> 36 Or KeyAscii <> 46 Or KeyAscii <> 48 _
Or KeyAscii <> 49 Or KeyAscii <> 50 Or KeyAscii <> 51 _
Or KeyAscii <> 52 Or KeyAscii <> 53 Or KeyAscii <> 54 _
Or KeyAscii <> 55 Or KeyAscii <> 56 Or KeyAscii <> 57 Then

KeyAscii = 0

End If

End Sub
 
T

Tom Ogilvy

% is 37

? asc("%")
37

Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _
As MSForms.ReturnInteger)

If not ((KeyAscii > 48 And KeyAscii <= 57) or KeyAscii = 46 _
or KeyAscii = 37) Then

KeyAscii = 0

End If

end if

--
Regards,
Tom Ogilvy

"DCSwearingen" <[email protected]>
wrote in message
news:D[email protected]...
 
D

DCSwearingen

Thank You!!

I had a typo in my earlier message. I did have 37 for the percen
sign in my code. I needed the parenthesis to combine the operations.
I'll have to remember that in the future!!

Again, thanks to all who post answers on this forum. I read a lot o
the answers, even if I have not run across the issue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top