List of Keycodes For "(" , ")" and "-"

T

Tru

I am trying to prevent users from using the: "-" (dash), "(" (open
parenthesis) and ")" (close parenthesis) in a phone number textbox. I have
to perform this task manually oppose to the input mask property because some
of our suppliers are international and the format for international phone
numbers are different. I can't set the [CompPhoneNo] Field to number because
some phone numbers begin with a zero.

Also, is there a list of all the Keycodes for the characters on the keyboard.
 
T

Tru

You the Man!
--
Thanx!


SteveM said:
Go to the code window and use the Help keyword 'Ascii' and you will be able
to print of the full character set.

While you are there, you may want to print off the list of vb keycode
constants too.

Steve

Tru said:
I am trying to prevent users from using the: "-" (dash), "(" (open
parenthesis) and ")" (close parenthesis) in a phone number textbox. I have
to perform this task manually oppose to the input mask property because some
of our suppliers are international and the format for international phone
numbers are different. I can't set the [CompPhoneNo] Field to number because
some phone numbers begin with a zero.

Also, is there a list of all the Keycodes for the characters on the keyboard.
 
A

Allen Browne

In the KeyPress event of the text box on your form, add this line:
Debug.Print KeyCode

Then use the form, and type the character you want (e.g. -.)
Open the Immediate Window (Ctrl+G) to see what the keycode value is.

With KeyPress (but not with KeyDown), the value is probably the same as:
? Asc("-")
 
A

Albert D. Kallal

just place the follwing epxresion in the after update setting (properoty
sheet) for any fax, phone pager number:

=RidesPhone3()


Then, in a standard code module, go:

Public Function RidesPhone3()

Dim ctlAct As Control

Set ctlAct = Screen.ActiveControl

If IsNull(ctlAct.Value) = True Then Exit Function


ctlAct.Value = OnlyNumbers(ctlAct.Value)


If Len(ctlAct.Value) = 7 Then
ctlAct.Value = gblRecRides!DefaultAreaCode & ctlAct.Value
End If


End Function

and:

Public Function OnlyNumbers(myphone As String) As String

Dim i As Integer
Dim mych As String

OnlyNumbers = ""

If IsNull(myphone) = False Then

For i = 1 To Len(myphone)
mych = Mid$(myphone, i, 1)
If InStr("0123456789", mych) > 0 Then
OnlyNumbers = OnlyNumbers & mych
End If
Next i
End If


End Function


So, you can highlight all 3 or 4 phone number fields on a form, and then
type in the expression

=RidesPhone3()

Thus, you can set all the "phone" fields on one form in "one shot" to use
that above code, and you don't even have to open up the code editor to
accomplish this.

Thus, for the "zillions" of phone numbers in a typical application, the
above will ONLY allow numbers...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top