Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Set Focus in Tab Control Sub Form?

    I have a main form with tab control for a subform

    When I click the tabbed subform how do I get the focus to go to the first field in the subform each time?

    Where do I put something like this lngTypeID.SetFocus in the sub form?

    Thanks, John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Let's say your tab control is named tabPages. You may get away with this:<pre>Private Sub tabPages_Change()
    tabPages.Pages(tabPages.Value).Controls(0).Form.Co ntrols(0).SetFocus
    End Sub</pre>

    If you want to name the first control on each subform explicitly, you'll have to write a Select Case statement to inspect the value of tabPages.Value.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Hi Hans

    The following gave a runtime error 438, obj dosen'r support this prop:

    TabCtl0.Pages(TabCtl0.Value).Controls(0).Form.Cont rols(0).SetFocus

    What's wrong with the above code?

    However the following works:

    Select Case Me.TabCtl0
    Case 0
    'MsgBox "Page 0 Permit Information"
    Case 1
    'MsgBox "Page 1 Notes"
    Case 2
    'MsgBox "Page 2 Applicants"
    Case 3
    DoCmd.GoToControl "Specifics" ' subform name
    DoCmd.GoToControl "lngSetFrontFootage" ' name of first control
    Case 4
    DoCmd.GoToControl "Approvals"
    DoCmd.GoToControl "lngReqApprCodeID"
    Case 5
    DoCmd.GoToControl "Inspections"
    DoCmd.GoToControl "lngReqInspCodeID"
    Case 6
    DoCmd.GoToControl "Fees"
    DoCmd.GoToControl "dtmIssueDate"
    Case 7
    DoCmd.GoToControl "[CO Data]"
    DoCmd.GoToControl "strFloor"
    Case 8
    DoCmd.GoToControl "Status"
    DoCmd.GoToControl "dtmDate"
    Case 9
    DoCmd.GoToControl "Calls"
    DoCmd.GoToControl "dtmDate"
    End Select


    Thanks, John

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Do you have a sub form on each of the tab pages?

    I tied Hans's code in that situation and it worked OK.

    From the look of your code below, pages 0, 1 and 2 may not have subforms.
    Regards
    John



  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Hi John

    Your right

    Page 0, 1 & 2 are tabs on the main form, knowing that what would have to change in Han's example?

    Thank, John

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    >>TabCtl0.Pages(TabCtl0.Value).Controls(0).Form.Co ntrols(0).SetFocus<<

    John,

    I think the problem here is the use of the Controls collection in this situation. I don't think you can depend on what you will find there. That is, you can't be certain of what kind of control you will find. In your case, Control(0) was probably a label, which can't get the focus. You would have to put this in a Do Loop to check the ControlType property.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    If the tab control is on the main form and there are subforms on its several tab pages, you don't need to reference the tab control or its pages at all. Any controls on a tab control page are really on the parent form. So if you have a subform, MySubform, on page 2 of your tab control on frmMain, all you need to do is reference it like this: Forms!MySubform. Forcus automatically goes to the first control in tab order for the subform that can receive the focus, so try:

    Forms!MySubform.Form.SetFocus
    Forms!MySubform.controls(0).SetFocus
    Charlotte

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Hi Charlotte

    You said try:
    Forms!MySubform.Form.SetFocus
    Forms!MySubform.controls(0).SetFocus

    This one worked for me:
    Me!ReqInspSubForm.Form!lngReqInspCodeID.SetFocus

    Thanks, John

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set Focus in Tab Control Sub Form? (A2k (9.0.3821) SR-1)

    Good. As long as it worked. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I just noticed that I had mistyped what I posted before anyhow. <img src=/S/blush.gif border=0 alt=blush width=15 height=15> Forms!MySubform.controls(0).SetFocus should have been Forms!MySubform.Form.controls(0).SetFocus.

    Tab controls can be especially confusing because you don't normally need to reference them at all. They're a sort of optical illusion that allows you to selectively present controls that are really on the parent form.
    Charlotte

Posting Permissions

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