Q: running an event when user presses ENTER from a txt box

A

A C

Hello

We have a form with login and password text boxes.
We would like the user to be able to enter the password and hit ENTER and
have the system execute the same code as if they had hit the OK button.

I can get this to work using the onKeyDown event and detecting ENTER, but my
question is:

How do I detect the value of the text box given that at this stage it is
still showing as NULL ? ie Access has not yet updated that text box's value
as the focus has not yet moved.

I have a workaround (below) but I dont like it, I want focus to stay in this
text box and I simply want Acess to pull out the currently entered value
without changing focus at all.

/code snip
Private Sub Password_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

' If user presses ENTER

Case 13

Me.OKButton.SetFocus 'move focus to cement the value into the text box
*********** I dont want to do this

Call OKButton_Click

End Select


End Sub


Thanks
A
 
B

Baz

A C said:
Hello

We have a form with login and password text boxes.
We would like the user to be able to enter the password and hit ENTER and
have the system execute the same code as if they had hit the OK button.

I can get this to work using the onKeyDown event and detecting ENTER, but my
question is:

How do I detect the value of the text box given that at this stage it is
still showing as NULL ? ie Access has not yet updated that text box's value
as the focus has not yet moved.

I have a workaround (below) but I dont like it, I want focus to stay in this
text box and I simply want Acess to pull out the currently entered value
without changing focus at all.

/code snip
Private Sub Password_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

' If user presses ENTER

Case 13

Me.OKButton.SetFocus 'move focus to cement the value into the text box
*********** I dont want to do this

Call OKButton_Click

End Select


End Sub


Thanks
A

Set the OK button's "Default" property to Yes. Pressing Enter will then
press the button.
 

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