Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox KeyPress problem

Status
Not open for further replies.

Tim8w

Programmer
Apr 8, 2003
44
US
I have a TextBox control called TextBoxTotal on my form. When I try and run the program, I get the following error:

"Procedure declaration does not match description of event or procedure having the same name"

Here is the sub in question

Private Sub TextBoxTotal_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
'Ok to type these keys
Case Else
KeyAscii = 0
End Select
End Sub

Something else curious, if I rename the sub to Text1_KeyPress the error goes away, but the sub never gets called. (I have no TextBox called Text1 defined on the form)

Any ideas?

Thanks,
Tim
 

Do you have an array of these textboxes? If not then remove the "KeyAscii As Integer" from the declaration.

Good Luck

 
The usual reason for that error is having 2 procedures with the same name. Do an Edit|Find for 'Sub TextBoxTotal_KeyPress' and make sure there's only one of them in scope. (i.e. on the form or in a code module)

Errmmm - vb5prgrmr - KeyAscii is the code of the key passed in all keypress events - are you thinking of Index?


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Removing the parameters doesn't help. All I'm trying to do is trap when a CR is typed into a singleline TextBox. There is no control array, just a single TextBox in the form. I have a global Form_KeyPress defined also, but it won't catch the CR in the TextBox.
 

Ahhhh....yeahhh, welll duhhh!!! Its Friday and my mind is else where, now if only my body can catch up!!!

 
All,

Found the problem. The TextBox I was using was from MS.Forms so the declaraction had to be as follows:

Private Sub TextBoxTotal_KeyPress(KeyCode As MSForms.ReturnInteger)
End Sub

Thanks,
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top