Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Condensing Task

I have a userform with 23 textboxes and 2 comboboxes. In an effort to
advance the cursor to the next textbox or combobox if the user hit the ENTER
key, I have the following for each, ie a total of 25 of these routines (with
appropriate adjustments to match):

Private Sub TextBox6_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Then Textbox7.SetFocus
End Sub

I was wondering if there was a way to condense to one routine and use SELECT
CASE, or IF-THEN?

I don't know what the first line would have to be (Private Sub...), but I am
thinking
along the lines that I would need to know the ACTIVE (current textbox), then
be able to advance using a variable, similar to below:

DIM b as Interger
b would need to be a value to represent active textbox
then code might look like this:
If KeyCode = 13 Then Textbox & (b+1).SetFocus

Thanks,
Les
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Condensing Task

I don't understand exactly what you are saying or how it is going to work. I
am still learning VBA Excel. I do have programming experience from other
languages from the 80's so I can guess there are ways to shorten what I want
to do, just don't know how to do it.

Les


"Nigel" wrote:

You will still need to detect the event for the control, however you might
consider using the Controls collection for the form to determine the next
control.


Me.Controls("TextBox" & b + 1).SetFocus

Pass the value of b from the current control.

On the face of it it does not save you a lot, but it might be useful if your
have other common code to run.

--

Regards,
Nigel




"WLMPilot" wrote in message
...
I have a userform with 23 textboxes and 2 comboboxes. In an effort to
advance the cursor to the next textbox or combobox if the user hit the
ENTER
key, I have the following for each, ie a total of 25 of these routines
(with
appropriate adjustments to match):

Private Sub TextBox6_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Then Textbox7.SetFocus
End Sub

I was wondering if there was a way to condense to one routine and use
SELECT
CASE, or IF-THEN?

I don't know what the first line would have to be (Private Sub...), but I
am
thinking
along the lines that I would need to know the ACTIVE (current textbox),
then
be able to advance using a variable, similar to below:

DIM b as Interger
b would need to be a value to represent active textbox
then code might look like this:
If KeyCode = 13 Then Textbox & (b+1).SetFocus

Thanks,
Les


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
Condensing data from 3D to 2D Garbin Excel Worksheet Functions 7 December 5th 07 06:29 PM
Condensing Formula phil2006 Excel Discussion (Misc queries) 6 June 7th 06 12:57 PM
Need help condensing with-end with code excelnut1954 Excel Programming 2 May 1st 06 03:49 PM
Condensing my worksheet Derek Witcher Excel Worksheet Functions 4 September 1st 05 03:59 PM
dialog box for active cell task to speed repeditive task Todd F.[_2_] Excel Programming 3 August 9th 05 02:30 PM


All times are GMT +1. The time now is 10:02 AM.

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

About Us

"It's about Microsoft Excel"