How do you test for a number, not a string?

  • Thread starter Thread starter Frederick Wilson
  • Start date Start date
F

Frederick Wilson

Hello,

Access XP

My table field property is set as a number

On my dataentry form the associated control sends an unfriendly
error/warning when a string is entered. I have tried to trap this error with
IsNumeric() in the beforeupdate for the control and in the on exit for the
control. However, I still get the system default error.

Additionally, after I click the ok button on the system warning, I try to
click my exit button which has

if me.dirty = true then me.undo
docmd.close

This still response with the system error. Not until I go back and change it
to a number can I continue or click exit.

What is the right timing to get this to work?

Thanks,
Fred
 
What is the right timing to get this to work?

I'd suggest using the *textbox's* BeforeUpdate event, not the Form's:

Private Sub txtMyTextbox_BeforeUpdate(Cancel as Integer)
If txtMyTextbox.Text & "" <> "" Then ' did the user enter anything?
If Not IsNumeric(txtMyTextbox.Text) Then
MsgBox "Please enter only numbers", vbOKOnly
Me.txtMyTextbox.Undo ' erase the user input
Cancel = True
End If
End If
End Sub
 
Back
Top