input mask question

P

Peter

Hi All
I'm sure the answer to this is easy but it's eluding me!

I have a field that I want operators to only be able to
enter numbers into. I have set the input mask to zeroes
and that works fine. The problem I have is the length of
the field - the field may contain a reference number of 4
or 5 digits or 20....if I set the input mask to 20 zeores,
it only allows a field of that length and nothing in
between.

Your assistance would be appreciate.

Thank you all.

Peter
 
M

Mark M

If your field is a number field, it should take care of itself. If your
field is a text field, then in the BeforeUpdate event, you could check to
see if the value is a numeric value with the IsNumeric() function. If it
passes, you're good; if it fails, you can tell them. Something like:

Private Sub Field1_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Field1) Then
If IsNumeric(Me.Field1) Then
MsgBox "Numeric"
Else
Cancel = True
Me.Field1.Undo
MsgBox "Not numeric"
End If
End If
End Sub
 
K

Klatuu

Not Correct, Mark. A 0 in an input mask means a numeric character is required.
Use a 9 instead, it means allow any numeric character and is optiona.
 
M

Mark M

You're right, Klatuu. Sometimes I make things seem a little more difficult
than they really are. I was thinking along the lines of not using an input
mask at all, instead of just making the digits optional. :)
 
P

Peter

Thanks for the replies - they're appreciated.

I tried the 9 route but that presents a slightly different
problem for me now because one thing I didn't mention is
that I don't want to have any spaces between the digits
for consistency.

I could always try writing a routine which strips the
spaces out but if there are any other things anyone can
think of it would be appreciated.

Thanks

Peter
 

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