Elseif clause is a variation of IF..THEN.....ELSE statement.By using this , we can control program flow.
Here, let be a field in the table as "age". Let the value in age cannot be less than 10 and greater than 60.So the code do check the value in the text box control named text1 is can be placed in the lost focus event of the text1 control.
A) Property :
Textbox |
B) Attaching Code to the Object :
Private Sub Text1_LostFocus() If Val(Text1.Text) < 10 Then MsgBox "age cannot be less than 10" Text1.SetFocus ElseIf Val(Text1.Text) > 60 Then MsgBox "age cannot be greater than 60" Text1.SetFocus Else MsgBox "age entered correctly" End If End Sub |
Refer : VB-10 : Set Focus(If-Then)
VB-12 : Set Focus(If-Then-Else-Endif)
=========================================================================
Back to Home & VB
Back to Home & VB