By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,392 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,392 IT Pros & Developers. It's quick & easy.

Phone Input Masks - Area Code

P: 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;;_" ?
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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, ma*******@byu.edu (Mark Lees) wrote:
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;;_" ?


Nov 12 '05 #2

P: n/a
Steve Jorgensen <no****@nospam.nospam> wrote in
news:j7********************************@4ax.com:
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. On 3 Feb 2004 22:21:24 -0800, ma*******@byu.edu (Mark Lees) wrote:
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;;_" ?



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
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.