VBA tab to next tab-stopped control (but no sendkeys!)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi folks,

I need a way to force the cursor to tab to the next control in the tab list.
Because of the nature of the form operations, I won't know what the 'next'
control is, and the autotab doesn't seem to work when the value is added via
code. I use autotab and a mask to move between controls when the inputting
is via the keyboard, but when the inputting utilizes a little number pad I
made on my form, that doesn't work.

Is there a way, via code, to force a tab. I'd prefer not to use sendkeys as
I understand it's generally frowned upon.

Thanks,
CW
 
The next control is the one with the next highest TabIndex.
You could loop through the controls to find the next number.

However, there are several issue here:
- If the control's TabStop is No, you skip that one and move on to the next.

- If the control's Enabled or Visible property is No, you skip it too.

- If you get to the end of the controls on the form, you will need to start
again from the lowest one.

- There may not actually be any next control.

- If the form has a Tab control, each Page of the tab control has its own
controls, and the controls within that page have their own tab order, so you
need to identify if the Parent of the control is a tab page, and handle it
accordingly. Similarly, if the control is the last visible, enabled control
that has a TabStop on the tab page, you need to identify what is the next
tab page, and loop through its controls. If there is no visible, enabled
control with a tab stop on that page, you will need to continue looping
through the pages, remembering that there may also be controls on the form
itself to handle.

If you are seriously interested in seeing how to loop through the controls
on a form to determine their ordering, see:
http://allenbrowne.com/AppFindAsUTypeCode.html
For example, ParentNumber() returns the PageIndex of the tab page that a
control is on.
 
Thanks for the reply, Allen.

I'm going to have to look at that a little more closes and see if I can
figure out what you're getting at here. I understand what looping through is
and all, but I don't see anything in that linked code that's making it all
click just yet.

I've found another solution I can go with, at least for now. I just
declared a string variable, made it equal to the name of the currently active
control, and then used a select case to tell the cursor where to go based on
where it is at the time.

Not quite what I'd call 'elegant', but it does work.

Thanks again,
CW
 
Back
Top