Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Check box to change the format of a text box

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Check box to change the format of a text box

Rachel,

place both these procedures behind your form & see if it does what you want.
the Exit routine ensures format is applied after user has updated entry.

Hope helpful

Private Sub chkmobile_Click()

With Me.txtphone

.Text = Replace(Replace(.Text, " ", ""), "-", "")

If Me.chkmobile.Value = True Then

.Text = Format(.Text, "0000-000-000")

Else

.Text = Format(.Text, "00-0000-0000")

End If

End With

End Sub

Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call chkmobile_Click
End Sub
--
jb


"Rachel" wrote:

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Check box to change the format of a text box

Hi John,
Sorry for the late response - I actually couldn't find my question after
posting it!!
Your codes worked perfectly, thank you so much!!

"john" wrote:

Rachel,

place both these procedures behind your form & see if it does what you want.
the Exit routine ensures format is applied after user has updated entry.

Hope helpful

Private Sub chkmobile_Click()

With Me.txtphone

.Text = Replace(Replace(.Text, " ", ""), "-", "")

If Me.chkmobile.Value = True Then

.Text = Format(.Text, "0000-000-000")

Else

.Text = Format(.Text, "00-0000-0000")

End If

End With

End Sub

Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call chkmobile_Click
End Sub
--
jb


"Rachel" wrote:

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Check box to change the format of a text box

Hi Rachel,
no worries - glad it worked & thanks for feedback.
--
jb


"Rachel" wrote:

Hi John,
Sorry for the late response - I actually couldn't find my question after
posting it!!
Your codes worked perfectly, thank you so much!!

"john" wrote:

Rachel,

place both these procedures behind your form & see if it does what you want.
the Exit routine ensures format is applied after user has updated entry.

Hope helpful

Private Sub chkmobile_Click()

With Me.txtphone

.Text = Replace(Replace(.Text, " ", ""), "-", "")

If Me.chkmobile.Value = True Then

.Text = Format(.Text, "0000-000-000")

Else

.Text = Format(.Text, "00-0000-0000")

End If

End With

End Sub

Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call chkmobile_Click
End Sub
--
jb


"Rachel" wrote:

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Check box to change the format of a text box

Assuming you have the default format as mentioned try the below checkbox
click event..

Private Sub chkmobile_Click()
txtphone.Text = IIf(chkmobile.Value, "0000-000-000", "00-0000-0000")
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Rachel" wrote:

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Check box to change the format of a text box

If the user type in the phone number before checking mobile then you can use
the below which would change the format of the existing number..

Private Sub chkmobile_Click()
txtphone.Text = Format(Replace(txtphone.Text, "-", ""), _
IIf(chkmobile.Value, "0000-000-000", "00-0000-0000"))
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Assuming you have the default format as mentioned try the below checkbox
click event..

Private Sub chkmobile_Click()
txtphone.Text = IIf(chkmobile.Value, "0000-000-000", "00-0000-0000")
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Rachel" wrote:

I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I
want them to be able to tick a check box (chkmobile) if the number is a
mobile number and the format of txtphone is to change to "0000-000-000". If
they then untick chkmobile the format returns to "00-0000-0000". Is this
possible?

Thanks :)

Reply
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
Check boxes and text strikethrough / color change Christine Excel Worksheet Functions 2 October 12th 09 09:30 PM
How to change the font size for text within check box? Eric Excel Discussion (Misc queries) 1 May 5th 09 11:50 AM
Change Date Format to Specific Text Format When Copying [email protected] Excel Discussion (Misc queries) 4 December 23rd 08 03:43 PM
how do I change the text size of a form check box volfinkinder New Users to Excel 1 April 13th 06 05:28 PM
Automatically change the text color when you check out the checkbo Dajana Excel Discussion (Misc queries) 1 November 7th 05 09:35 PM


All times are GMT +1. The time now is 12:17 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"