textbox validation

endri81

Registered User.
Local time
Today, 05:53
Joined
Jul 5, 2010
Messages
121
How to validate a textbox in order to accept only integers from 1-20 and in all the other cases show a message box for non accepted values?
 
And what do you want in the text box if an invaid entry is made?
 
Rabbie:Smthg Like sorry only numbers from 1-20 allowed.
 
Put this in the control's BEFORE_Update event

Code:
Private Sub [COLOR=red]NameOfControl[/COLOR]_BeforeUpdate(Cancel As Integer)
If (Me![COLOR=red]NameOfControl[/COLOR]) > 0 And (Me![COLOR=red]NameOfControl[/COLOR]) < 21 Then
    ' do nothing
Else
    MsgBox "Wrong Format, choose numbers between 1-21"
    Cancel = True
    Me![COLOR=red]NameOfControl[/COLOR].Undo
End If
End Sub

Change the marked in red to the correct name of your control

JR
 

Users who are viewing this thread

Back
Top Bottom