W
Walter
I have found a workaround for my problem, but I'm curious as to why the problem exists in the first place. On my userform, I have four textboxes that are required. I don't want the user to be able to enter any other data until the first field has been filled, then the second, third and fourth. After that, the rest of the form is free game. I tried first to use SetFocus to send the user back to the textbox, but instead, the cursor moved on to the next box. This happened in every instance where I used SetFocus to go to a textbox. It works fine if I use it to send the focus to a command button. My workaround was to add this:
Private Sub UserForm_Activate()
If CaseNoBox.Text = "" Then
cbxCaseType.Enabled = False
cbxLName.Enabled = False
cbxFName.Enabled = False
DeftAddressBox.Enabled = False
cbxCity.Enabled = False
cmbStates.Enabled = False
ZipBox.Enabled = False
NumCharges.Enabled = False
SpinButton1.Enabled = False
cbxCharge1.Enabled = False
btnNext.Enabled = False
btnPrint.Enabled = False
End If
....(there's a lot more stuff in this Sub)
Then I enabled specific controls as in the following example:
Private Sub CaseNoBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CaseNoBox.Text = "" Then
MsgBox "This is a required field. You must enter a number before proceeding.", vbOKOnly, "Required Field"
MinEntryForm.CaseNoBox.SetFocus
Else
cbxCaseType.Enabled = True
cbxLName.Enabled = True
End If
End Sub
This works, but it seems that it would be a lot easier if I could just make the focus continually return to the same textbox whenever the user tries to leave, until data is entered in the box.
Any ideas?
Private Sub UserForm_Activate()
If CaseNoBox.Text = "" Then
cbxCaseType.Enabled = False
cbxLName.Enabled = False
cbxFName.Enabled = False
DeftAddressBox.Enabled = False
cbxCity.Enabled = False
cmbStates.Enabled = False
ZipBox.Enabled = False
NumCharges.Enabled = False
SpinButton1.Enabled = False
cbxCharge1.Enabled = False
btnNext.Enabled = False
btnPrint.Enabled = False
End If
....(there's a lot more stuff in this Sub)
Then I enabled specific controls as in the following example:
Private Sub CaseNoBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CaseNoBox.Text = "" Then
MsgBox "This is a required field. You must enter a number before proceeding.", vbOKOnly, "Required Field"
MinEntryForm.CaseNoBox.SetFocus
Else
cbxCaseType.Enabled = True
cbxLName.Enabled = True
End If
End Sub
This works, but it seems that it would be a lot easier if I could just make the focus continually return to the same textbox whenever the user tries to leave, until data is entered in the box.
Any ideas?