albertc30
Well-known Member
- Joined
- May 7, 2012
- Messages
- 1,091
- Office Version
- 2019
- Platform
- Windows
Hi all.
Firstly, as always, a much big thank you for all the help provided in the past and currently. This is much appreciated.
Secondly, another issue. This issue being I have a textbox for customer phone. I need to format this to
Now, some of my existing code already does part of this, and I did had it formatting to 00000 000 000 but this was by way of beforevalidate.
I have since then added code to change function and now it's all messed up.
Any help much appreciated.
Thank you all for your time.
Cheers.
Firstly, as always, a much big thank you for all the help provided in the past and currently. This is much appreciated.
Secondly, another issue. This issue being I have a textbox for customer phone. I need to format this to
- only allow 11 digits, no more, no less,
- it can't use nothing else other than numbers,
- to be displayed in the box as 00000 000 000.
Now, some of my existing code already does part of this, and I did had it formatting to 00000 000 000 but this was by way of beforevalidate.
I have since then added code to change function and now it's all messed up.
Code:
Private Sub tbnctel_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
'
' Application.EnableEvents = False
' If Len(tbnctel.Value) < 11 Then
' Cancel = True
' MsgBox "Error! Contact number not long enough.", vbCritical
' tbnctel.Value = Left(Me.tbnctel.Value, 11) '<--Not sure why this is even here!
' tbnctel.Value = ""
' tbnctel.SetFocus
' Else
' tbnctel = Format(tbnctel, "00000 000 000") 'This worked fine without the Change code bellow...
' End If
' Application.EnableEvents = True
End Sub
Private Sub tbnctel_Change()
Dim i, text_count As Integer
If Len(Me.tbnctel.Value) > 0 Then
text_count = 0
For i = 1 To Len(Me.tbnctel.Value)
If IsNumeric(Mid(Me.tbnctel.Value, i, 1)) = False Then
Me.tbnctel.Value = Replace(Me.tbnctel.Value, Mid(Me.tbnctel.Value, i, 1), "")
text_count = text_count + 1
End If
Next i
If text_count > 0 Then
MsgBox "Only numbers are allowed!"
Exit Sub
End If
End If
tbnctel = Format(tbnctel, "00000 000 000") 'might work here?
End Sub
Any help much appreciated.
Thank you all for your time.
Cheers.