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

  • Follow


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.


0
Reply Utf 3/4/2007 11:26:10 PM

XP wrote:
> 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.

-- 
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com 


0
Reply Rick 3/4/2007 11:31:33 PM


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" wrote:

> XP wrote:
> > 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.
> 
> -- 
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt   at   Hunter   dot   com 
> 
> 
> 
0
Reply Utf 3/5/2007 12:35:03 AM

XP wrote:
> 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.

-- 
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com 


0
Reply Rick 3/5/2007 1:21:22 AM

3 Replies
448 Views

(page loaded in 0.07 seconds)


Reply: