Connecting Tech Pros Worldwide Help | Site Map

Phone Input Masks - Area Code

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 06:53 PM
Mark Lees
Guest
 
Posts: n/a
Default Phone Input Masks - Area Code

I want to create an input mask for a phone number and I would like the
area code to always be (801). However, I want the users to be able to
edit it if necessary.
Would it look like this = !"(801) 000\-0000;;_" ?

  #2  
Old November 12th, 2005, 06:53 PM
Steve Jorgensen
Guest
 
Posts: n/a
Default Re: Phone Input Masks - Area Code

Masks are not very flexible. They are so inflexible, in fact, that they are
borderline useless and tend to annoy users more than help them.

You could make the default value for the control to be (801) and let the user
edit from there, then use a BeforeUpdate handler to validate the input and an
AfterUpdate handler to clean up the formatting if desired. The user can press
F2 to unhighlight the area code and start typing at the next character
position.

Here's some air code...

Private Sub txtPhone_BeforeUpdate(Cancel As Integer)
If IsNull(Me!txtPhone) Or IsEmpty(Me!txtPhone) Then Exit Sub
If Not ( _
Me!txtPhone Like "(###)###-####" Or _
Me!txtPhone Like "(###)#######" _
) Then
Cancel = True
End If
End Sub

Private Sub txtPhone_AfterUpdate()
If IsNull(Me!txtPhone) Or IsEmpty(Me!txtPhone) Then Exit Sub
If Me!txtPhone Like "(###)#######" Then
Me!txtPhone = _
Left$(Me!txtPhone, Len("(###)###")) & _
"-" & Mid$(Me!txtPhone, Len("(###)###") + 1)
End If
End Sub

On 3 Feb 2004 22:21:24 -0800, mark_lees@byu.edu (Mark Lees) wrote:
[color=blue]
>I want to create an input mask for a phone number and I would like the
>area code to always be (801). However, I want the users to be able to
>edit it if necessary.
>Would it look like this = !"(801) 000\-0000;;_" ?[/color]

  #3  
Old November 12th, 2005, 06:54 PM
Rolf Østvik
Guest
 
Posts: n/a
Default Re: Phone Input Masks - Area Code

Steve Jorgensen <nospam@nospam.nospam> wrote in
news:j74120dbup2c440e6v8d233ri9gmugd1cr@4ax.com:
[color=blue]
> Masks are not very flexible. They are so inflexible, in fact, that they
> are
> borderline useless and tend to annoy users more than help them.
>
> You could make the default value for the control to be (801) and let the
> user
> edit from there, then use a BeforeUpdate handler to validate the input >
> and an
> AfterUpdate handler to clean up the formatting if desired. The user can
> press
> F2 to unhighlight the area code and start typing at the next character
> position.[/color]
[color=blue]
> On 3 Feb 2004 22:21:24 -0800, mark_lees@byu.edu (Mark Lees) wrote:
>[color=green]
>>I want to create an input mask for a phone number and I would like the
>>area code to always be (801). However, I want the users to be able to
>>edit it if necessary.
>>Would it look like this = !"(801) 000\-0000;;_" ?[/color]
>
>[/color]

And to free the user from the task of pressing F2 to unlight the area code
use the SelStart property in the GotFocus property of the control.

E.g.

Private Sub Controlname_GotFocus()
Controlname.SelStart = 100
End Sub


--
Rolf
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.