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

How do I tie an event to hitting the enter key?

Status
Not open for further replies.

tvsmvp

Technical User
Aug 17, 2006
59
US
Okay -this answer's gotta be simple, but I can't find anything in access help.

How do I tie an event to someone hitting the "enter" key after putting info into a particular text box?
 
Right click on the the textbox
build event
code builder
change the event of the sub via the dropdowns

Private Sub F5_KeyDown(KeyCode As Integer, Shift As Integer)
If vbKeyReturn = KeyCode Then
MsgBox F5.Value
End If

End Sub

[yinyang] Tranpkp [pc2]
 
Thanks - that almoooost works. I follow your code - till it comes to passing the value of the text box (Me!tbKeyWordsLike.Value). I haven't been able to get that. Should I add an "after update" to the text box?

Private Sub tbKeyWordsLike_KeyDown(KeyCode As Integer, Shift As Integer)
If vbKeyReturn = KeyCode Then
cbLookup_Click
End If
End Sub

------------

Private Sub cbLookup_Click()
mywords = Me!tbKeyWordsLike.Value
End Sub
 
I dont' even code Access; thats the first time I even tried anythng like that.
Your original request works; thats how you use the event to map to the return key.
what you're trying to do now is calling external function/sub.
What are trying to pass I don't see u 'passing' anything that next sub has no arguments and the original event has the value of the field accessbile already anyways.


Private Sub tbKeyWordsLike_KeyDown(KeyCode As Integer, Shift As Integer)
If vbKeyReturn = KeyCode Then
tbKeyWordsLike.value
End If
End Sub


[yinyang] Tranpkp [pc2]
 
I got it to work - I'd made a mistake by using the .value property of the textbox instead .text. In the end, I was able to enter info into the text box, hit the enter key - and have the vba use the text from that tb, as I'd hoped. Simple now that I see it.

Private Sub tbKeyWordsLike_KeyDown(KeyCode As Integer, Shift As Integer)
If vbKeyReturn = KeyCode Then
cbLookup_Click
End If
End Sub

followed by:

Private Sub cbLookup_Click()
mywords = Me!tbKeyWordsLike.Text
{misc code using text from "mywords" here}
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top