checking for correct Chr in string

  • Thread starter atlantis43 via AccessMonster.com
  • Start date
A

atlantis43 via AccessMonster.com

I have a cbo in which are entered surname,prename;Date of birth. It is
important that the comma be a comma, and that the semicolon be a semicolon.
Is there any way that I can analyze the characters entered (as they are typed)
, to insure that they are not, mistakingly, a period (instead of a comma) or
a colon
(instead of a semicolon). Any help would be appreciated.
TIA, Richard
 
P

pietlinden

atlantis43 said:
I have a cbo in which are entered surname,prename;Date of birth. It is
important that the comma be a comma, and that the semicolon be a semicolon.
Is there any way that I can analyze the characters entered (as they are typed)
, to insure that they are not, mistakingly, a period (instead of a comma) or
a colon
(instead of a semicolon). Any help would be appreciated.
TIA, Richard

This is a mutant, but it's a test/example. If you trap the key pressed
in the KeyPress event of your control, you can reject/discard the
characters you don't want in your control. The following code rejects
the semi-colon, period, and colon.


Private Sub Text0_KeyPress(KeyAscii As Integer)
'---Use this if you want to the code to respond differently to
different keys
' Select Case KeyAscii
' Case 46 'period
' KeyAscii = 0
' Case 58 'colon, I think...
' KeyAscii = 0
' Case 59 'semi-colon
' KeyAscii = 0
' Case Else 'do nothing
' End Select

'---or this one if you just want to throw away/ignore a fixed set of
keys.
Select Case KeyAscii
Case 58, 46, 59 '---list of the asc(":") values that you want
to reject
KeyAscii = 0
Case Else 'do nothing
End Select
End Sub

yes, it's a screwy example. You'd use one or the other....
 
A

atlantis43 via AccessMonster.com

Piet;Thanks for reply, which seems to be just what I seek. Only problem I
have is: how do I call this sub?
I'm entering "Text0KeyPress in my keypress event for my cbo, but I'm getting
errmsg "sub or function not defined. (with or without the parenteses). What
am I missing?
TIA, Richard

I have a cbo in which are entered surname,prename;Date of birth. It is
important that the comma be a comma, and that the semicolon be a semicolon.
[quoted text clipped - 6 lines]
This is a mutant, but it's a test/example. If you trap the key pressed
in the KeyPress event of your control, you can reject/discard the
characters you don't want in your control. The following code rejects
the semi-colon, period, and colon.

Private Sub Text0_KeyPress(KeyAscii As Integer)
'---Use this if you want to the code to respond differently to
different keys
' Select Case KeyAscii
' Case 46 'period
' KeyAscii = 0
' Case 58 'colon, I think...
' KeyAscii = 0
' Case 59 'semi-colon
' KeyAscii = 0
' Case Else 'do nothing
' End Select

'---or this one if you just want to throw away/ignore a fixed set of
keys.
Select Case KeyAscii
Case 58, 46, 59 '---list of the asc(":") values that you want
to reject
KeyAscii = 0
Case Else 'do nothing
End Select
End Sub

yes, it's a screwy example. You'd use one or the other....
 
P

pietlinden

Probably the most foolproof way of doing it is to copy this part into
the KeyPress event of your control (the textbox).

Select Case KeyAscii
Case 58, 46, 59 '---list of the asc(":") values that you want to
reject
KeyAscii = 0
Case Else 'do nothing
End Select

to get the KeyPress event of your control... right-click on the control
in design view, select the KeyPress event, and then when you get the
code window, paste in the above code..
 
A

atlantis43 via AccessMonster.com

yup! worked perfectly! Your first msg seemed to imply that I needed it as a
separate function.
Thanks again, Richard
 
A

atlantis43 via AccessMonster.com

yup! worked perfectly! Your first msg seemed to imply that I needed it as a
separate function.
Thanks again, Richard
 
A

atlantis43 via AccessMonster.com

yup! worked perfectly! Your first msg seemed to imply that I needed it as a
separate function.
Thanks again, Richard
 
A

atlantis43 via AccessMonster.com

yup! worked perfectly! Your first msg seemed to imply that I needed it as a
separate function.
Thanks again, Richard
 
Top