mardi 27 décembre 2016

IF statement not working in VBA

I am self-learning VBA and trying to write a little program does the following

1.asks users to enter a number between 10 to 20 in a textbox
2. When a button is clicked, the code will check the number entered in the textbox.If it is between 10 and 20, then a message will be displayed. If the number entered is not between 10 and 20 then the user will be invited to try a gain, and whatever was entered in the textbox will be erased.

Private Sub Command0_Click()
Me.Text3.SetFocus
inumber = Val(Text3.Text)
If Form_customer_test >= 10 & inumber <= 20 Then
MsgBox ("The number you entered is: ") & inumber
Else
Text3.Text = ""
MsgBox ("Please try again")
End If

End Sub

However, I don't think the else part of my codes is working. If I enter 5, it will display 5 instead of the message box. Could anyone please let me know if I have missed anything at all.

Thanks in advance. Happy Holidays.

Aucun commentaire:

Enregistrer un commentaire