Changing the default button on my form based on text input
Hi all. Question.
I have a default button (cmd1) on my form which works great.. The user hits enter at any time and it is the active button... but I've just added a text field (txt2) and another command button (cmd2) that would only be pressed when text is entered into this new field (txt2). Is there a way to now switch the default to this new cmd2 when text is entered into the txt2?
Thanks all! :)
jk
Re: Changing the default button on my form based on text input
You could set the focus to the button
VB Code:
Private Sub Text2_LostFocus()
if len(text1.text) > 0 then cmd2.SetFocus
End Sub
Re: Changing the default button on my form based on text input
Doesn't quite work.. The field will need to accept 4 - 6 digit numbers. Using this code, I input the first number and the focust jumps.. have to click back in the text field, input the second number, the focus jumps again.. etc.
Re: Changing the default button on my form based on text input
sorry. i edited it after i noticed that.
Re: Changing the default button on my form based on text input
Try this:
VB Code:
Private Sub Text2_LostFocus()
If Len(text1.Text) < 4 Or Len(text1.Text) > 6 Then
cmd2.SetFocus
End if
End Sub
Cheers,
RyanJ
Re: Changing the default button on my form based on text input
You don't need to SetFocus to a specific command button in order to make it the default. Command buttons have a Default property that you can set to True to make it the default. When any given command button's Default property is set to True, all others are automatically set to False.
Re: Changing the default button on my form based on text input
Thx Martin! I was still having the "jump focus" problem with the other code. This makes it much easier! Should have figured that out on my own! Next time. :)
Thx to all who responded.
Re: Changing the default button on my form based on text input
Thanks for trying to let us know that your question was answered. However the only way to make the green checkmark show up in the thread list is to edit the first post and add the checkmark there.