Connecting Tech Pros Worldwide Help | Site Map

Phone Input Masks - Area Code

  #1  
Old November 12th, 2005, 07:53 PM
Mark Lees
Guest
 
Posts: n/a
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, 07:53 PM
Steve Jorgensen
Guest
 
Posts: n/a

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, 07:54 PM
Rolf Østvik
Guest
 
Posts: n/a

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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyphenated Name Field Larry R Harrison Jr answers 14 November 13th, 2005 12:02 PM
Change Input mask in code F. Michael Miller answers 7 November 13th, 2005 10:53 AM