Hi i got a tiny question about those basic stuff.
There are "If textbox1.text ="" then
msgbox ="correct" " commands
But is there any "force" command like
"If text1.text ="122" then
msgbox ="It must be 123" ?
Printable View
Hi i got a tiny question about those basic stuff.
There are "If textbox1.text ="" then
msgbox ="correct" " commands
But is there any "force" command like
"If text1.text ="122" then
msgbox ="It must be 123" ?
Your question is not clear...:)
orCode:If text1.text="122" then
msgbox "it has to be 123 like this"
text1.text="123"
end if
Code:If text1.text="122" then
msgbox "it has to be 123 , plase do type it!!!"
text1.selstart=0
text1.sellength=len(text1.text)
text1.setfocus
exit sub 'exit the sub (means not executing anyother code below here in that sub"
end if
Or perhaps this which won't allow the user to leave Text1 until it's correct.
Code:Private Sub Text1_Validate(Cancel As Boolean)
If Text1.Text <> "123" Then
MsgBox "Text1 Must be 123"
Cancel = True
End If
End Sub
If you want to "force" a user to input "123" and nothing else is accepted then why even have the user enter anything at all? Just put "123" in the Textbox and lock it so user can't change it.
I'm guessing that the OP wants to create a password verifier.Quote:
Originally Posted by jmsrickland
Or you could verify it like this too. Its the same as the other methods, only I would consider it more user friendly.
Code:Dim holdcursor As Boolean
holdcursor = False
If Text1.Text <>"123" Then 'or whatever you want it to be
MsgBox "Incorrect value. The value needs to be 123."
'here it is your choice to follow either way of those below
'if you want to "force" your value
Text1.Text = "123"
'and if you simply want to put the cursor back to the textbox and verify it
holdcursor = True
Else
holdcursor = False
End If
Private Sub Text1_LostFocus()
If holdcursor Then Text1.SetFocus
End Sub