On hit enter key, run button on click code

B

BlueWolverine

Hey,
MS Access 2003 on XP PRO.

I have a search panel. It has a few fields to search from. I have a button
that runs the search.

I would like the act of hitting the enter key on the keyboard while in a
search parameter field to execute the code behind the button, instead of
merely moving the cursor to the next field.

Anyway to do that?
Thanks
 
L

Linq Adams via AccessMonster.com

If you go to the Properties Sheet for your command button the click on the
Other tab, you'll see a Property named Default. If you change this from No to
Yes, anytime you hit enter the OnClick code for your command button will be
executed. Is that what you're looking for?
 
B

BlueWolverine

Is there any way to aim it? The default thing works but, not as adaptably as
I'd hope.

Is there anyway to make a certain field aim to a certain button? Such that
hitting enter in field A runs the code for Button A while hitting enter in
field B runs the code for button B?

Thanks though, your method will work well enough.
 
L

Linq Adams via AccessMonster.com

You could use the KeyDown event for each textbox. Remember, if you've just
entered data and are still in the textbox, using Me.FieldA, for instance,
will pop a "Null" error. To refer to the data you've entered in a textbox
***while*** still in the textbox, you have to use the Text property, i.e. Me.
FieldA.Text

Private Sub FieldA_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
'FieldA Code Here
KeyCode = 0
End If
End Sub

Private Sub FieldB_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
'FieldB Code Here
KeyCode = 0
End If
End Sub

Private Sub FieldC_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
'FieldC Code Here
KeyCode = 0
End If
End Sub
 
L

Linq Adams via AccessMonster.com

Don't know what code you have behind your button, but as to your question
about

"Is there anyway to make a certain field aim to a certain button?"

from a command button, you can refer to the last field you were in with

Screen.PreviousControl.Name

to get it's name, or with

Screen.PreviousControl.Value

to get it's value.
 

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