Get contents and close form when [Enter] key is pressed

X

XP

Using Office 2003 and Windows XP;

I have a simple form with a single text box that I would like to code so the
user can just press the [Enter] key when done and the data will be captured
and the form will close.

How does one go about coding that?

Thanks much in advance.
 
R

Rick Brandt

XP said:
Using Office 2003 and Windows XP;

I have a simple form with a single text box that I would like to code
so the user can just press the [Enter] key when done and the data
will be captured and the form will close.

How does one go about coding that?

Thanks much in advance.

Create a button and put code in its Click event...

DoCmd.Close acform, Me.Name

Make the button invisible and set its Default property to True. Its code will
run when the <Enter> key is pressed.
 
X

XP

Really?

Does the button need to be in any particular spot, like overlapping the text
box or anything?

Rick Brandt said:
XP said:
Using Office 2003 and Windows XP;

I have a simple form with a single text box that I would like to code
so the user can just press the [Enter] key when done and the data
will be captured and the form will close.

How does one go about coding that?

Thanks much in advance.

Create a button and put code in its Click event...

DoCmd.Close acform, Me.Name

Make the button invisible and set its Default property to True. Its code will
run when the <Enter> key is pressed.
 
X

XP

Hi Rick, it's not working...

I placed the button on the form and made it invisible. I set the button's
Default property to "YES";

But, when I press Enter, nothing happens...any idea what I doing wrong?

Thanks much for your help.

Rick Brandt said:
XP said:
Using Office 2003 and Windows XP;

I have a simple form with a single text box that I would like to code
so the user can just press the [Enter] key when done and the data
will be captured and the form will close.

How does one go about coding that?

Thanks much in advance.

Create a button and put code in its Click event...

DoCmd.Close acform, Me.Name

Make the button invisible and set its Default property to True. Its code will
run when the <Enter> key is pressed.
 
X

XP

Hi Rick,

I got it to work, but I had to keep it visible. I made it smaller than my
text box and then placed it underneath that control; works great; thanks.

Rick Brandt said:
XP said:
Using Office 2003 and Windows XP;

I have a simple form with a single text box that I would like to code
so the user can just press the [Enter] key when done and the data
will be captured and the form will close.

How does one go about coding that?

Thanks much in advance.

Create a button and put code in its Click event...

DoCmd.Close acform, Me.Name

Make the button invisible and set its Default property to True. Its code will
run when the <Enter> key is pressed.
 
R

Rick Brandt

XP said:
Hi Rick,

I got it to work, but I had to keep it visible. I made it smaller
than my text box and then placed it underneath that control; works
great; thanks.

Hmm, I have only used that a couple of times and was unaware that the button had
to be visible. Buttons also can be set to transparent. Perhpas that would have
worked.
 

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