I have a userform that performs some validation checks on the data entered.
The validation executes on the _AfterUpdate event in the textboxes
Where the data entered is incorrect I am clearing the entry and trying to set the focus back to the textbox but it just isn't working.
On one for it doesn't seem to set the focus anywhere on the form and on another it is setting the focus to a textbox that is a few TabIndex values away from the one in use.
It's been a while since I built a userform but I recall this being a very simple action to perform.
The code from the form where it isn't setting the focus anywhere is below
This is the code where is is setting the focus to several TabIndex values away
The validation executes on the _AfterUpdate event in the textboxes
Where the data entered is incorrect I am clearing the entry and trying to set the focus back to the textbox but it just isn't working.
On one for it doesn't seem to set the focus anywhere on the form and on another it is setting the focus to a textbox that is a few TabIndex values away from the one in use.
It's been a while since I built a userform but I recall this being a very simple action to perform.
The code from the form where it isn't setting the focus anywhere is below
Code:
Private Sub txtJobNo_afterupdate()
Sheets("Data").Range("Data_JobNo") = txtJobNo
If Sheets("Data").Range("Data_ValidJobNo") = "Yes" Then
Else
MsgBox ("The 'Formatt Job No' entered already exists in the stored jobs." & vbCr & vbCr & _
"Enter a different 'Formatt Job No'"), vbExclamation, "Invalid Formatt Job No"
Sheets("Data").Range("Data_JobNo") = ""
txtJobNo = ""
txtJobNo.SetFocus
Exit Sub
End If
Sheets("Data").Range("Data_JobNo") = ""
txtClient.Enabled = True
txtContactNo.Enabled = True
txtContact.Enabled = True
txtEmail.Enabled = True
txtClientAddress.Enabled = True
txtInstallAddress.Enabled = True
txtClientRef.Enabled = True
txtJobName.Enabled = True
txtQuoteNo.Enabled = True
txtNotes.Enabled = True
End Sub
Code:
Private Sub txtStartDate_afterupdate()
Dim mbConfirm
If IsDate(CDate(txtStartDate)) Then
If CDate(txtStartDate) < dtFormDate Then
mbConfirm = MsgBox("The 'Start Date' is prior to todays date." & vbCr & vbCr & _
"Click 'OK' to confirm or 'Cancel' to enter another date.", vbOKCancel, "Confirm Date")
If mbConfirm = vbOK Then
Else
txtStartDate = ""
txtStartDate.SetFocus
End If
Else
End If
End If
End Sub