Textbox Format

G

gti_jobert

Hi all,

I have a textbox on my userform and neeeeed it formatted. When the user
enters it I want them to enter a 10 digit number only but also have it
display a '-' in the middle of the number.

for example,

#####-##### (the textbox should always display the '-' in the middle of
the textbox. Is this possible? I have previously tried:


Code:
--------------------
txtPartno.Text = Format(txtPartno.Text, "#####-#####")
--------------------


but have had no joy, any help would be much appreciated.

Taa in advance!
 
I

Ian

Possibly not the most elegant method, but this will put a - immediately
after the 5th character in TextBox1

Private Sub TextBox1_Change()
If Len(TextBox1.Text) = 5 Then TextBox1.Text = TextBox1.Text & "-"
End Sub
 
G

gti_jobert

Hi again,

Thanks for the promt reply! I have tried what you have suggested and
works quite well. I'm not sure if it can be done in VBA, but is there a
way of using an activex control to mask the textbox? I may have seen
somewhere on the web that it can be done in VB6?!

Does anyone know how to do it in VBA?

Thanks Again!
 
D

Dave Peterson

gti_jobert wanted to know if he/she can mask the textbox so that the format can
be "built-in".

Excel's textboxes don't support this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top