How to validate unbound field is numeric?

KeithWilliams

Registered User.
Local time
Today, 18:59
Joined
Feb 9, 2004
Messages
137
Hi,

I have an unbound text field named [Text_TargetTotalUpdateable].

To validate it, I added a validation rule:
IsNumeric([Text_TargetTotalUpdateable])

However, this does not accept any value, even an integer.

How can I validate this unbound field to require it to be numeric. Can I give it a data type, as a bound field would have?

Thanks,
Keith.
 
Hi Stephen,

Thanks for the reply. However, General Number doesn't really give the behaviour I want. It allows the user to key in alpha characters, and only validates when they tab away. Also I put 2 in decimal places but it ignores this, and allows a value with more than 2 d.p. to be stored, even if it only displays 2 places when focus is not on the field.

However, I don't like the way Edit Masks work, either, so can't use those.

I'm currently working on putting some complex validation logic into the KeyPress event, and cancelling the event when the user types an invalid character. Messy, so I'd greatly appreciate any further hints.

Thanks,
Keith.
 
Hi Rich,

The value does not need to be stored in the database. I use it to generate values to populate other fields, which are bound to the database. So I don't understand how I could use a bound field.

Thanks,
Keith.
 
I had a look at using a keypress event and it wouldn't have to be too complicated. Something like
Code:
If (KeyAscii >= 48 And KeyAscii <= 57) Then
Else
MsgBox "Please enter only numeric characters"
DoCmd.CancelEvent
End If

would probably do the trick.
 
Just found a potential problem with that though. It also prevents you using backspaces etc. If you adjust the if statement though I guess you can get around it.
 
Hi Stephen,

Thanks for that, yes it gets a bit more complex, you need to allow ASCII characters 8, 9, 10 and 13. I'm also validating for decimals, depending on other factors I require only integers or allow up to 2 decimal places.

Its working OK now, but far from elegant coding!

Keith.
 

Users who are viewing this thread

Back
Top Bottom