vbaprogammer
Programmer
I have a text box controlled by a checkbox which, on exit, cannot be empty. I prefill the text box with the format (999,999-99-99) [txtSelectLoanNumber].
On exit the code checks for content and length, and displays a message box if not correct. Otherwise it reformats the text input by the user, and moves to the next text box (txtSelectLender).
However, if I wish to change my mind, and uncheck the checkbox, I still get the message "Invalid Loan Number". Actually it should clear the textbox (txtSelectLoanNumber) and then disable the textbox.
If the loan number is incorrect, the cursor should move back to the txtSelectLoanNumber text box, but it also moves to the next box.
Here's my code. I'm hoping someone can point out the problem. (Remember, this is Word and some events and properties in Access are not available here.)
Thanks,
Dan
(Each statement should be on one line below.)
'===Checkbox to enable text boxes
'=======
Private Sub chkSelectLoanNumber_Click()
If Me.chkSelectLoanNumber Then
Me.txtSelectLoanNumber = "" 'Whether true or false, clear text boxes
Me.txtSelectLender = ""
Me.txtSelectLoanNumber.Enabled = Me.chkSelectLoanNumber.Value
Me.txtSelectLender.Enabled = Me.chkSelectLoanNumber.Value
On Error Resume Next
Me.txtSelectLoanNumber.SetFocus
End If
End Sub
Private Sub txtSelectLoanNumber_Enter()
If Len(txtSelectLoanNumber) = 0 And txtSelectLoanNumber <> "999,999-99-99" Then
Me.txtSelectLoanNumber.Text = "999,999-99-99"
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
Else
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
End If
End Sub
Private Sub txtSelectLoanNumber_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.txtSelectLoanNumber.Text = "999,999-99-99" Or Len(Me.txtSelectLoanNumber.Text) < 10 Or Len(Me.txtSelectLoanNumber.Text) > 13 Then
MsgBox "Invalid Loan Number"
Cancel = True
Me.txtSelectLoanNumber.SetFocus 'Doesn't work
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
Else
Me.txtSelectLoanNumber.Text = Format(Me.txtSelectLoanNumber.Text, "000\,000\-00\-00"
End If
End Sub
[sig][/sig]
On exit the code checks for content and length, and displays a message box if not correct. Otherwise it reformats the text input by the user, and moves to the next text box (txtSelectLender).
However, if I wish to change my mind, and uncheck the checkbox, I still get the message "Invalid Loan Number". Actually it should clear the textbox (txtSelectLoanNumber) and then disable the textbox.
If the loan number is incorrect, the cursor should move back to the txtSelectLoanNumber text box, but it also moves to the next box.
Here's my code. I'm hoping someone can point out the problem. (Remember, this is Word and some events and properties in Access are not available here.)
Thanks,
Dan
(Each statement should be on one line below.)
'===Checkbox to enable text boxes
'=======
Private Sub chkSelectLoanNumber_Click()
If Me.chkSelectLoanNumber Then
Me.txtSelectLoanNumber = "" 'Whether true or false, clear text boxes
Me.txtSelectLender = ""
Me.txtSelectLoanNumber.Enabled = Me.chkSelectLoanNumber.Value
Me.txtSelectLender.Enabled = Me.chkSelectLoanNumber.Value
On Error Resume Next
Me.txtSelectLoanNumber.SetFocus
End If
End Sub
Private Sub txtSelectLoanNumber_Enter()
If Len(txtSelectLoanNumber) = 0 And txtSelectLoanNumber <> "999,999-99-99" Then
Me.txtSelectLoanNumber.Text = "999,999-99-99"
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
Else
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
End If
End Sub
Private Sub txtSelectLoanNumber_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.txtSelectLoanNumber.Text = "999,999-99-99" Or Len(Me.txtSelectLoanNumber.Text) < 10 Or Len(Me.txtSelectLoanNumber.Text) > 13 Then
MsgBox "Invalid Loan Number"
Cancel = True
Me.txtSelectLoanNumber.SetFocus 'Doesn't work
Me.txtSelectLoanNumber.SelStart = 0
Me.txtSelectLoanNumber.SelLength = 13
Else
Me.txtSelectLoanNumber.Text = Format(Me.txtSelectLoanNumber.Text, "000\,000\-00\-00"
End If
End Sub
[sig][/sig]