Full Version: Telephone Number Input Mask
UtterAccess Forums > Microsoft® Access > Access Forms
dbtech1
The last page on the wizard for making a telephone number input mask asks if you want to store the data with the symbols (800) 555-1212 or without the symbols 8005551212.
hich is best to do...? If I store the symbols, do I have to trim them off when I retrieve the data...?
theDBguy
Hi Dave,
My personal choice would be to "NOT" store the symbols but that's just my humble opinion...
datAdrenaline
I do not store the symbols ... I actually avoid input masks too .. I have used the controls events to strip any extraneous symbols --- that is what worked best for my particular user base.
dbtech1
Hi Brent,
o you by chance have an example of a control event you would use to strip the symbols from a telephone number?
This would be my first time using the input mask - It's not the most user friendly thing, as I've found I can click my mouse on the third character spot and it will just start typing from there. I wanted to try it on a new form of mine though, as I've the last time I put out a phone number field, I ended up storing each and every way somebody could imagine to type it out!
theDBguy
Hi DB,
If you are using an Input Mask, you can leave out the second argument and the table should not store the literals with the data. For example:
!\(999") "000\-0000; ;_
instead of:
!\(999") "000\-0000;0;_
Hope that helps...
datAdrenaline
Sure ...
On the control used to hold the Phone number (I will assume the name of "Phone"), use the AfterUpdate of that control ...
CODE
Private Sub Phone_AfterUpdate()
    
    If Len(Me.Phone & "") > 0 Then _
        Me.Phone = RemSpecial(Me.Phone)
    
End Sub

Click here for a post that has the RemSpecial() code in it.
-----
Another approach is to prevent anything but numbers being typed in the field with the KeyPress event
CODE
Private Sub Phone_KeyPress(KeyAscii As Integer)
    
    'Add what ever you want here
    Const conInValidChars = "abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+=-`{[}]:;"" '<,>.?/|\"
    
    Dim strKeyPressed As String
    
    strKeyPressed = Chr(KeyAscii)
    
    If InStr(1, conInValidChars, strKeyPressed, vbTextCompare) > 0 Then
        KeyAscii = 0  'Disables the key that was pressed
    End If
End Sub
dbtech1
Hi Brent,
Thanks for your help...
I was doing some searching around the net and found another way to do this as well...
CODE
Private Sub Text1_KeyPress(KeyAscii As Integer)
     If KeyAscii < 48 Or KeyAscii > 57 Then
          KeyAscii = 0
     End If
End Sub

Also, I was wondering if there is a way to add a hyphen after the user types in 3 characters... I tried the code below, but it moved the cursor to the beginning of the text box after it ran...
CODE
If Len(Me.txtPhone.Text) = 3 Then
     Me.txtPhone.Text = Me.txtPhone.Text & "-"
End If

I figured that you can change a KeyAscii code, like in the code below (changes a 1 to a 5), but can you send more than one...? If so, this would allow me to send the hyphen...
CODE
If KeyAscii = 49 Then
     KeyAscii = 53
End If

Any thoughts...?
theDBguy
Hi,
see that you abandoned the Input Mask altogether. I don't use it very often either but in your situation, I thought that placing a 0 in third argument of the Input Mask would answer your question about storing the hyphens and parens (see my previous post above).
To answer the problem of clicking anywhere in the textbox and being able to start in the middle, you can place code in the GotFocus event like:
Me.Phone.SelStart = 0
Me.Phone.SelLength = 0
Just my 2 cents...
dbtech1
Hi DBGuy,
eah, I was thinking of abandoning the IM, mainly becasue I don't want a user to click in the middle of the box and be able to start in the middle. I did see your post, and removed the hyphens from being stored, which is good, but I want it to be user friendly as well. I would be willing to use the IM if I could get the cliocking in the middle thing figured out.
Check out the attached test database. I just tried your suggestion and it didn't seem to work. When you tab through to the Phone field, it obvioudly starts in the correct position, but you can still click to the middle of the field. Any other ideas on how to handle this?
Thanks,
DB
Click to view attachment
theDBguy
Sorry, I can't open your file right now because I don't have Acc2007 on this machine.
If the SelStart code works for the Focus event, maybe you could also add it to the Click event of the Phone textbox.
Hope that helps...
dbtech1
That did it...!!!
Thanks
theDBguy
Glad to hear that! We are all happy to help. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.