+ Reply to Thread
Results 1 to 3 of 3

VBA Control Tab Index

  1. #1

    VBA Control Tab Index

    I have several forms within an excel project and am trying to refer to
    the controls, in the VBA code, on a given form by their tab index. For
    example, let's say I want to set focus and active the control with an
    index of 3.

    I have been searching and am unable to get it right.

    Can this be done?

    Thanks,
    Smithb2


  2. #2
    George Nicholson
    Guest

    Re: VBA Control Tab Index

    AFAIK, you'll need to loop through the entire Controls collection and, when
    you find the control with the right tab index, set focus to it and exit the
    loop. I've never done this while referencing TabIndexes but I suspect that
    "On Error Resume Next" may be your best friend in this case since not all
    controls will have a TabIndex property. There may be other issues involved
    that I am unaware of.

    (untested aircode)

    Call SetFocusByTabIndex(Me,3)

    Sub SetFocusByTabIndex(frm as Form, iTab as Integer)
    On Error Resume Next
    Dim ctl as Control

    For each ctl in frm.Controls
    If ctl.TabIndex = iTab Then
    ctl.SetFocus
    Exit For
    End If
    Next ctl
    End Sub

    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.


    <[email protected]> wrote in message
    news:[email protected]...
    >I have several forms within an excel project and am trying to refer to
    > the controls, in the VBA code, on a given form by their tab index. For
    > example, let's say I want to set focus and active the control with an
    > index of 3.
    >
    > I have been searching and am unable to get it right.
    >
    > Can this be done?
    >
    > Thanks,
    > Smithb2
    >




  3. #3

    Re: VBA Control Tab Index

    Thanks George...............I will see what I can come up with


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1