Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I am having trouble working with a particular textbox in my userform.
The user enters 10 digits into a textbox. This represents the 10 digits of a telephone number excluding any special characters.
The code below tests and manipulates the entry the user has made.
This works wonderfully when the user enters the number initially, but as soon as the user selects another control to use (for instance one of the three checkboxes that are enabled), this code triggers again. Since the value had been formatted as part of the code that previously ran, the IsValid function fails. This shouldn't happen.
I'm unsure what I must do to avoid this behaviour.
The user enters 10 digits into a textbox. This represents the 10 digits of a telephone number excluding any special characters.
The code below tests and manipulates the entry the user has made.
Code:
Private Sub p_tn2_AfterUpdate()
Stop
Dim tendigit As String
'Stop
With p_tn2
tendigit = .Text
If IsValid(tendigit) = False Then
MsgBox "Please enter telephone number as 10 numbers, no special characters (##########)."
.Text = ""
.SetFocus
Exit Sub
End If
ptn2 = CDbl(.Text)
ac = Left(ptn2, 3)
ec = Right(ptn2, 4)
mc = Mid(ptn2, 4, 3)
ptn2str = ac & "." & mc & "." & ec
.Text = ptn2str
p_tn2_h.Enabled = True 'checkbox
p_tn2_c.Enabled = True 'checkbox
p_tn2_b.Enabled = True 'checkbox
p_tn3.Enabled = True
frm_submit.Visible = True
btn_submit.Enabled = True
End With
End Sub
This works wonderfully when the user enters the number initially, but as soon as the user selects another control to use (for instance one of the three checkboxes that are enabled), this code triggers again. Since the value had been formatted as part of the code that previously ran, the IsValid function fails. This shouldn't happen.
I'm unsure what I must do to avoid this behaviour.