Greetings all,
I have a UserForm I am using for data input with an XLS file. I have a textbox that I am using for phone number entry that has a cell in the XLS sheet as the control source. In the BeforeUpdate method, I call a function that does a check for 7 or 10 digits and if the check clears, returns a formatted value:
After the BeforeUpdate, the textbox is showing the correct format, but the cell in the XLS sheet is showing the "Non-formatted" value.
For example:
I type "1234567890" in the textbox in my UserForm and hit enter. The cell in the XLS sheet shows "1234567890", but the Textbox is showing "(123) 456-7890". It seems the control source is being updated with the value of the textbox prior the the BeforeUpdate event fires. If the event results in a Cancel=True, the orginal value is restored.
Any insights would be greatly appreciated.
Thank you,
msc
I have a UserForm I am using for data input with an XLS file. I have a textbox that I am using for phone number entry that has a cell in the XLS sheet as the control source. In the BeforeUpdate method, I call a function that does a check for 7 or 10 digits and if the check clears, returns a formatted value:
Code:
Private Sub txtC1_Phone_BeforeUpdate(ByVal cancel As MSForms.ReturnBoolean)
txtC1_Phone = Check_Phone(Me.txtC1_Phone, cancel, "Contact #1 Phone Number")
End Sub
Public Function Check_Phone(objContl As Object, ByVal Cancel As MSForms.ReturnBoolean, strText As String)
Dim varWkr As Variant, i As Integer
varWrk = Replace(objContl, "(", "")
varWrk = Replace(varWrk, ")", "")
varWrk = Replace(varWrk, "-", "")
varWrk = Replace(varWrk, " ", "")
Select Case Len(varWrk)
Case Is = 0
'
' Empty
'
Case Is = 7
Check_Phone = Format(" " & varWrk, "###-####")
Case Is = 10
Check_Phone = Format(varWrk, "(###) ###-####")
Case Else
Check_Phone = objContl
Cancel = True
MsgBox "The " & strText & _
" you've entered does not seem complete, Please Check", _
vbInformation + vbOKOnly, "Please Check"
End Select
End Function
After the BeforeUpdate, the textbox is showing the correct format, but the cell in the XLS sheet is showing the "Non-formatted" value.
For example:
I type "1234567890" in the textbox in my UserForm and hit enter. The cell in the XLS sheet shows "1234567890", but the Textbox is showing "(123) 456-7890". It seems the control source is being updated with the value of the textbox prior the the BeforeUpdate event fires. If the event results in a Cancel=True, the orginal value is restored.
Any insights would be greatly appreciated.
Thank you,
msc