Validating first two numbers entered into a text box

  • Thread starter Thread starter gb
  • Start date Start date
G

gb

Hello all

Have a form with a text box (Forms!frm_International!International_Number).
When a number is entered, I'd like the number to be validated, to ensure it
starts with 00.

How could I perform this by code, please?

Thanks

gb
 
Hi gb,

you can use BeforeUpdate event:

Private Sub Texto0_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Texto0) Then
If Not Len(Me.Texto0) >= 2 Then
Cancel = True
MsgBox "Wrong number", vbCritical
Exit Sub
End If
If Not Left$(Me.Texto0, 2) = "00" Then
Cancel = True
MsgBox "Wrong number", vbCritical
Exit Sub
End If
End If
End Sub

Luiz Cláudio C. V. Rocha
São Paulo - Brazil
 
Hello all

Have a form with a text box (Forms!frm_International!International_Number).
When a number is entered, I'd like the number to be validated, to ensure it
starts with 00.

The validations suggested will answer your direct question, but... be
sure that the Table field to which this control is bound is of Text
type, not Number. Even if this "number" consists only of digits, it's
not actually a quantity used for calculations; the number 0035 and the
number 35 are *the same number*, and in a Number field will be stored
identically.

John W. Vinson[MVP]
 
Thanks to each of you - they both work :)

gb

Hello all

Have a form with a text box (Forms!frm_International!International_Number).
When a number is entered, I'd like the number to be validated, to ensure it
starts with 00.

How could I perform this by code, please?

Thanks

gb
 
Back
Top