PC Review


Reply
Thread Tools Rate Thread

Check box to change the format of a text box

 
 
Rachel
Guest
Posts: n/a
 
      29th Nov 2009
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 With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      29th Nov 2009
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

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      29th Nov 2009
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 With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      29th Nov 2009
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 With Quote
 
Rachel
Guest
Posts: n/a
 
      3rd Dec 2009
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

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      3rd Dec 2009
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format text box with check box Rachel Microsoft Excel Programming 1 3rd Dec 2009 12:08 PM
Change format of check boxes ginble07 Microsoft Word Document Management 4 9th Jul 2009 01:47 PM
Change Date Format to Specific Text Format When Copying adambush4242@hotmail.com Microsoft Excel Misc 3 23rd Dec 2008 03:43 PM
VBA automatically change text format into general format? Nicawette Microsoft Excel Programming 2 13th Jun 2006 01:35 PM
make table query - change number format to text format Mark Microsoft Access Queries 1 13th Dec 2003 12:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:43 PM.