Link Text Box to Button with Enter Key?

G

Guest

I have a form with a few command buttons, and one text field. If the user
enters a record ID into the text field and presses the "Print Report" button,
a detailed report of that record pops up. How can I link the text box to the
button such that when the user types in an ID and hits Enter instead of
clicking the button, the button click event results?

Thanks,

Eric
 
G

Guest

As I see it, you have two alternatives:
1. Put the button click code in the AfterUpdate event of your textbox.
2. You could call the button click procedure in this event

To call the button click event just type the name of the procedure, for
example btn1_Click in the AfterUpdate event of the textbox.

Steve
 
G

Guest

Thanks, I did the latter and it works fine.

SteveM said:
As I see it, you have two alternatives:
1. Put the button click code in the AfterUpdate event of your textbox.
2. You could call the button click procedure in this event

To call the button click event just type the name of the procedure, for
example btn1_Click in the AfterUpdate event of the textbox.

Steve
 
J

Jeff Boyce

Eric

Are you open to an alternate approach?

Requiring the user to know/remember IDs may be less than user-friendly. If
your form uses a combobox that allows the user to "look up" IDs (or maybe
even look up Persons, or Customers or whatever the IDs are assigned to),
users find this much easier than IDs.

And you could use the AfterUpdate event of the combobox to open the
report...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

missinglinq via AccessMonster.com

In Design View, click on the button to select it
Goto Properties - Others
Set Default to Yes

Now whenever <Enter> is hit the button's code will execute. Obviously, only
one command button per form can have this set to Yes!
 
G

Guest

This particular box is a "quickie" in which the user is expected to already
know the ID. There is another, more complex form through which the user can
create the report using multiple selection criteria.

Thanks for the input.
 
G

Guest

One thing I hadn't thought of is if the user doesn't press the Enter key but
instead types a value and then clicks the button! In this scenario the
AfterUpdate event would fire (triggering the button click) and then the
button click would be triggered again by clicking the button...

If this is a possibility, you may want to use the KeyDown event. There you
could detect the Enter key and call the button click procedure.

Steve
 

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