PC Review


Reply
Thread Tools Rate Thread

Condensing Task

 
 
WLMPilot
Guest
Posts: n/a
 
      11th Jan 2008
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 With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      11th Jan 2008
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
(E-Mail Removed)



"WLMPilot" <(E-Mail Removed)> wrote in message
news:C2A85278-D754-4226-B80D-(E-Mail Removed)...
>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 With Quote
 
WLMPilot
Guest
Posts: n/a
 
      11th Jan 2008
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
> (E-Mail Removed)
>
>
>
> "WLMPilot" <(E-Mail Removed)> wrote in message
> news:C2A85278-D754-4226-B80D-(E-Mail Removed)...
> >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Font Condensing =?Utf-8?B?VGJ1Z3M=?= Microsoft Word Document Management 2 2nd Mar 2007 04:18 AM
Condensing Code =?Utf-8?B?c3RldmU=?= Microsoft Excel Programming 1 23rd Aug 2006 08:37 PM
Condensing Formula phil2006 Microsoft Excel Misc 6 7th Jun 2006 12:57 PM
Stop IE6 'condensing' open browsers on task bar?? =?Utf-8?B?SjEy?= Windows XP General 8 12th Sep 2005 02:45 PM
Condensing =?Utf-8?B?TWFyYw==?= Windows XP MovieMaker 0 9th Feb 2004 08:31 AM


Features
 

Advertising
 

Newsgroups
 


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