Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check for Enter key and change focus?

I have a Userform which has a textbox, two Option Buttons and a Ad
button.

The user type something in the box, chooses one of the 2 choices an
press Add (To add the data to a Listbox)

Now what I need is that the user can type the number on the textbo
and press Enter to add the data to the listbox (Assuming the optio
buttons are already chosen), but neither KeyUp or KeyPress events seem
to listen to the Enter Key on the keyboard.

How can this be done?

Another question is that when the user press the add button I woul
like the cursor to go back to the textbox so that he can press Add an
right after type the new data (Without having to click on the text bo
again).

Hopefully they can be done.

Best Regards

Noo

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check for Enter key and change focus?

Look at the exit event.

Look at setfocus for positioning the cursor.

--

Regards,
Tom Ogilvy

"NooK " wrote in message
...
I have a Userform which has a textbox, two Option Buttons and a Add
button.

The user type something in the box, chooses one of the 2 choices and
press Add (To add the data to a Listbox)

Now what I need is that the user can type the number on the textbox
and press Enter to add the data to the listbox (Assuming the option
buttons are already chosen), but neither KeyUp or KeyPress events seems
to listen to the Enter Key on the keyboard.

How can this be done?

Another question is that when the user press the add button I would
like the cursor to go back to the textbox so that he can press Add and
right after type the new data (Without having to click on the text box
again).

Hopefully they can be done.

Best Regards

NooK


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check for Enter key and change focus?

Thanks, the SetFocus worked out nicelly, but the Exit event is not wha
I am looking for because if the user for example clicks anywhere els
in the form (Say the listbox) whatever is in the textbox wil
automatically be aded to it and that's not right, Only if the use
presses Enter is the stuff to be added.

Isn't there anyway at All?

Best Regards

Noo

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check for Enter key and change focus?

The keyup and keydown events are triggered by a Return.

--
Regards,
Tom Ogilvy

"NooK " wrote in message
...
Thanks, the SetFocus worked out nicelly, but the Exit event is not what
I am looking for because if the user for example clicks anywhere else
in the form (Say the listbox) whatever is in the textbox will
automatically be aded to it and that's not right, Only if the user
presses Enter is the stuff to be added.

Isn't there anyway at All?

Best Regards

NooK


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check for Enter key and change focus?

Sorry for the delay on the answer, I was away on vacation with no acces
to internet.

Are you sure Keyup and Keydown are triggered by Enter because i
doesn't do it here.

I did

Private Sub tbData_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVa
Shift As Integer)
MsgBox (KeyCode)
End Sub

And when I press any button on the textbox I get a msgbox saying it'
code but when I press Enter nothing appears and the focus changes t
the next control.

Best Regards

Noo

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check for Enter key and change focus?

From Help for the Keyup and Keydown events (so yes, Enter does trigger the
event except for the exception cited). Also note the particular information
on Enter when the focus switches - so you should be using the KeyDown. Of
course, a quick trip to the help screen would have cleared this all up for
you.

The KeyDown and KeyUp events do not occur under the following circumstances:

a.. The user presses enter on a form with a command button whose Default
property is set to True.


b.. The user presses esc on a form with a command button whose Cancel
property is set to True.
The KeyDown and KeyPress events occur when you press or send an ANSI key.
The KeyUp event occurs after any event for a control caused by pressing or
sending the key. If a keystroke causes the focus to move from one control to
another control, the KeyDown event occurs for the first control, while the
KeyPress and KeyUp events occur for the second control.



--

Regards,

Tom Ogilvy



"NooK " wrote in message
...
Sorry for the delay on the answer, I was away on vacation with no access
to internet.

Are you sure Keyup and Keydown are triggered by Enter because it
doesn't do it here.

I did

Private Sub tbData_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
MsgBox (KeyCode)
End Sub

And when I press any button on the textbox I get a msgbox saying it's
code but when I press Enter nothing appears and the focus changes to
the next control.

Best Regards

NooK


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase size of a Forms Check Box (click on to enter check mark) 718Satoshi Excel Discussion (Misc queries) 0 August 17th 07 01:52 AM
how can I check for cell focus inside a spreadsheet ? EdwardAlanzo Excel Worksheet Functions 2 May 16th 07 12:41 AM
How do I get the focus on a check box? reneatwork New Users to Excel 1 September 15th 06 02:52 PM
must press enter 2x to move cell focus Lynn Excel Discussion (Misc queries) 0 March 18th 05 06:05 PM
Setting form controls focus and enter key John T Ingato Excel Programming 1 October 6th 03 05:13 PM


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"