mask and allow negative values problem

K

Keith G Hicks

I have a text box where I want to allow the user to enter at most 5 digits
to the left of the decimal and 3 to the right. I'd normally mask this as
follows:

99999.999

I also need to allow them to enter negatives but I DON'T want to allow for 6
digits to the left of the decimal. I still want 5. But it appears that I'm
stuck with this so that they can enter the minus sign and still have 5
digits. The trouble is that this also now would allow 6 digits for positive
values.

#99999.999

Is there a way to mask this so that I get the behavior my client requires?

Thanks,

Keith
 
K

Keith G Hicks

A2k by the way.

Thanks but it is a numeric field. That's got nothing to do with it. If a
text box is bound to a numeric field, the user can still type in any ole
thing he wants. An error doesn't occur until he attempts to post it. I need
to mask it so he cannot enter an invalid value in the first place. In a
language like Delphi I can mask a text box so that the +/- has nothing to do
with the digits being typed. I'd do something like this: [+/-]99999.99. The
user can ONLY type 5 numeric values to the left of the decimal and can
precede them by either a "+" or "-" at his option. They're separate issues.
I need to know if this can be done in Access.

Keith
 
G

Guest

In your form text box use this as the input mask ---
#####.###

--
KARL DEWEY
Build a little - Test a little


Keith G Hicks said:
A2k by the way.

Thanks but it is a numeric field. That's got nothing to do with it. If a
text box is bound to a numeric field, the user can still type in any ole
thing he wants. An error doesn't occur until he attempts to post it. I need
to mask it so he cannot enter an invalid value in the first place. In a
language like Delphi I can mask a text box so that the +/- has nothing to do
with the digits being typed. I'd do something like this: [+/-]99999.99. The
user can ONLY type 5 numeric values to the left of the decimal and can
precede them by either a "+" or "-" at his option. They're separate issues.
I need to know if this can be done in Access.

Keith
 
K

Keith G Hicks

That doesn't solve the problem. Try it. It still only allows you to type in
4 digits if you use a minus sign. And it has the added flaw of letting a
user type in things like "----.98" which generates an error on post.

I'm guessing there's no good masking solution to this and I'll have to write
BeforeUpdate code to handle it or I just am stuck with using 6 mask
characters which could allow 6 digits to the left or a combination of both.
Ugh. I wish Access had more complex masking capabilities (like "regular
expressions" masking).
 
P

Pieter Wijnen

Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim NotNeg As Double

If IsNull(Me.Text0.Value) Then Exit Sub

NotNeg = Abs(Me.Text0.Value)
If NotNeg > 99999 Then
Cancel=True
ElseIf NotNeg - Clng(NotNeg) < 0.001 Then
Cancel=True
End If
If Cancel Then
Beep
'MsgBox "Naughty, Naughty"
End If

End Sub

HtH

Pieter
 

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

Similar Threads

changing the Phone Number Input Mask to all for extensions 2
check decimal and if numeric 3
Input Mask Error Message 4
Input mask 2
input mask 2
input mask question 4
Input Mask 1
date masking on form 1

Top