Be careful with all these warnings, it's a nuisance to users. Let the computer do the work, that's what they are for.
So, check the key press and accept only number input by, for each textbox, validating the key press:
- Private Sub YourTextbox_KeyPress(KeyAscii As Integer)
-
-
ValidateKeyPress KeyAscii
-
-
End Sub
-
-
-
Private Sub ValidateKeyPress(ByRef KeyAscii As Integer)
-
-
Const KeyNone As Integer = 0
-
-
Select Case KeyAscii
-
Case vbKeyBack
-
' Accept backspace.
-
Case Is < vbKey0
-
' Not a number key.
-
KeyAscii = KeyNone
-
Case Is > vbKey9
-
' Not a number key.
-
KeyAscii = KeyNone
-
End Select
-
-
End Sub
Likewise, accept the Null and replace it when updating the record:
- Private Sub Form_BeforeUpdate(Cancel As Integer)
-
-
Me!Textbox1.Value = Nz(Me!Textbox1.Value, 0)
-
Me!Textbox2.Value = Nz(Me!Textbox2.Value, 0)
-
' ...
-
Me!Textbox9.Value = Nz(Me!Textbox9.Value, 0)
-
-
End Sub
However, even that can be too much coding if more than a few textboxes (or other controls) are to be handled.
If so, turn to
WithEvents. "How", is a story longer than to be told here, but study an example as this:
https://github.com/GustavBrock/VBA.ModernTheme.