LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Format a textbox

Where is the TextBox located (on the worksheet or on a User Form)? If on the
worksheet, where did you get it from (the Drawing or Control Toolbox
toolbar)?

--
Rick (MVP - Excel)


"JacyErdelt" wrote in message
...
Thank you for your response. I am trying to insert your code into mine,
but I
am having some problems. When I insert exactly what you wrote and then run
it, the code is not executed because it is not associated with that
specific
textbox (which I think is expected because I assume "textbox1" is a
generic
name). However when I change that to specifically refer to the textbox
(which
is named "txtPhone") I get the following compile error; Procedure
declaration
does not match description of event or procedure having the same name.
This
is what the code looks like when I get the compile error;

Private Sub txtPhone_KeyUp(ByVal KeyCode As MSForms.ReturnInteger,
ByValShift As Integer)
If IsNumeric(Chr(KeyCode)) Then
If Len(Me.txtPhone) = 1 Then Me.txtPhone = "(" & Me.txtPhone
If Len(Me.txtPhone) = 4 Then Me.txtPhone = Me.txtPhone & ")"
If Len(Me.txtPhone) = 8 Then Me.txtPhone = Me.txtPhone & "-"
Else
If Len(Me.txtPhone) < 0 Then
Me.txtPhone = Left(Me.txtPhone, Len(Me.txtPhone) - 1)
End If
End If
End Sub

If "textbox1" is not just a generic reference to the textbox, then you
need
to know that I actually have 7 textboxes in my userform and the phone
number
is 5th in the tab order, but I have no idea what number it was given when
I
created it. Your help is greatly appreciated. Thank you.



"Per Jessen" wrote:

Hi

Sure it can be done.
In addition to this I would set the MaxLength (Properties) of the TextBox
to
13 to limit the number of digits after the hypen to 4.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If IsNumeric(Chr(KeyCode)) Then
If Len(Me.TextBox1) = 1 Then Me.TextBox1 = "(" & Me.TextBox1
If Len(Me.TextBox1) = 4 Then Me.TextBox1 = Me.TextBox1 & ")"
If Len(Me.TextBox1) = 8 Then Me.TextBox1 = Me.TextBox1 & "-"
Else
If Len(Me.TextBox1) < 0 Then
Me.TextBox1 = Left(Me.TextBox1, Len(Me.TextBox1) - 1)
End If
End If
End Sub

Regards,
Per

"JacyErdelt" skrev i meddelelsen
...
Could anyone tell me how I might be able to format a textbox to auto
format
as a person is entering data. For instance when a person is entering
the
phone number (555)555-5555, the 1st 3 digits wills automatically be
place
within the parenthesis and the hypen will be placed when the next 3
digits
have been entered. I know i can format the box after it has LostFocus,
but
all the time we use advanced stand-alone programs that can be setup to
do
it
as the user is entering info and I thought maybe VBE could do it too.
If
you
have any suggestions, let me know. Thank you.






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextBox format? Pas Excel Discussion (Misc queries) 5 April 25th 10 11:13 PM
TextBox format? AOU Excel Discussion (Misc queries) 4 June 12th 07 11:24 PM
Textbox format Oggy Excel Programming 2 January 25th 07 06:30 PM
TextBox Format grahammal Excel Discussion (Misc queries) 3 March 29th 06 01:35 PM
Textbox Format gti_jobert Excel Programming 5 January 19th 06 08:11 PM


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"