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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect pressing enter on TextBox 2

Status
Not open for further replies.

mobbarley

IS-IT--Management
Mar 4, 2004
22
0
0
AU
Hey.

I'm trying to detect a carrage return when somone is typing in a textbox and have it automatically call a procedure. Here is what I have so far:

Private Sub txtSwipeCard_KeyPress(KeyAscii As MSForms.ReturnInteger)
If KeyAscii = "13" Then
call whatever()
Me.Hide
End If
End Sub

Does not seem to work! any ideas? thanks ;)
 
I use the KeyUp event to trigger the function.
Code:
Private Sub txtSwipeCard_KeyUp(KeyCode As Integer)
If KeyCode = vbKeyReturn Then
call whatever()
Me.Hide
End If
End Sub
Good luck
 
That does not seem to work.. the focus switches to a command button next to it..

using a msgbox to show the KeyCode works, but not for the enter key.

Is an option on the form wrong? Any ideas?
 
Private Sub txtSwipeCard_KeyPress(KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 13 Then
call whatever()
Me.Hide
End If
End Sub

just remove the double quote.

Please pardon the grammar.
Not good in english.
 
Is there any text box named txtSwipeCard in your form?
Sorry, just currious.
 
Yes there is :) Its actually going to be entered from a PS/2 Magnetic card reader which is programed to insert a CR at the end of a read.

I found the problem, I was using a textbox from MSForms 2.0 because of it's sexy etched form effect, this seems to handle the CR differently, inserting a standard textbox solved the problem..

Thanks for the help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top