replace zero when null

L

Lisa

I have what should be a simple problem to solve. So far I have only been
annoyed not being able to solve it.

I have a numeric field on a form. I don't want a popup message if a value is
not valid (null or alphanumeric). Rather I just want a zero to be entered.

Example: A user sees '100' that he wants to change to zero. He should be
able to tab to the field, press 'Delete'. The field will go blank and when
he tabs to the next field a zero (0) will be displayed. Similar if he by
mistake enters a letter(s).

Thanks for any help
 
M

Michel Walsh

In a form? Under the control AfterUpdate procedure handling the event, for
the control (not for the form), make the check, something like:


Private Sub Text0_AfterUpdate()
If IsNull(ControlName.Value) then
ControlName.Value=0
ElseIf Not IsNumeric(ControlName.Value) then
ControlName.Value = 0
End if
End Sub




Sure, also add a default value of 0, so a new record will also get a 0, at
creation time.


Hoping it may help,
Vanderghast, Access MVP
 
A

Allen Browne

Remove any validation rules on the field, and make sure its Required
property is No.

You can then use code in its AfterUpdate event to test if it IsNull(), and
if so assign it a zero.

Use the KeyPress event to block any characters that should not be permitted,
by setting KeyAscii to zero. You probably should allow + and -, period, and
backspace. (A side effect of this is that any hotkeys won't work while this
text box has focus.)
 

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