Results 1 to 9 of 9

Thread: SetFocus issue

  1. #1
    Join Date
    Sep 2005
    Posts
    220

    Unanswered: SetFocus issue

    I have a login form that I use and on this form, the user specifies which category they wish to update. Based on their answer, I then open another form and only display the tab for the correct category. The following code works if they choose Category 1, but when they choose Category 2 or 3, I get an error saying "You can't hide a control that has the focus"


    Code:
    Select Case Forms!frmLogin!category_frame  'depending on which category the user wants to work on, we need to set focus to the correct tab
    
            Case Is = 1
        
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages(0).SetFocus              ' set focus to Category 1 tab
                Forms!frm_Main!TabCtl0.Pages.Item(1).Visible = False  ' make category 2 page not visible
                Forms!frm_Main!TabCtl0.Pages.Item(2).Visible = False  ' make category 3 page not visible
            
                Call UnselectOptionButtons   ' reset all the option buttons to blanks
            
            Case Is = 2
            
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages.Item(0).Visible = False  ' make category 1 page not visible
                Forms!frm_Main!TabCtl0.Pages(1).SetFocus              ' set focus to Category 2 tab
                Forms!frm_Main!TabCtl0.Pages.Item(2).Visible = False  ' make category 3 page not visible
        
                Call UnselectOptionButtons
            
            Case Is = 3
            
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages.Item(0).Visible = False  ' make category 1 page not visible
                Forms!frm_Main!TabCtl0.Pages.Item(1).Visible = False  ' make category 2 page not visible
                Forms!frm_Main!TabCtl0.Pages(2).SetFocus              ' set focus to Category 3 tab
                
                Call UnselectOptionButtons
    
            End Select

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Do your SetFocus first, then hide the other controls.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Sep 2005
    Posts
    220
    No luck

    Code:
    Select Case Forms!frmLogin!category_frame  'depending on which category the user wants to work on, we need to set focus to the correct tab
    
            Case Is = 1
        
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages(0).SetFocus              ' set focus to Category 1 tab
                Forms!frm_Main!TabCtl0.Pages.Item(1).Visible = False  ' make category 2 page not visible
                Forms!frm_Main!TabCtl0.Pages.Item(2).Visible = False  ' make category 3 page not visible
            
                Call UnselectOptionButtons   ' reset all the option buttons to blanks
            
            Case Is = 2
            
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages(1).SetFocus              ' set focus to Category 2 tab
                Forms!frm_Main!TabCtl0.Pages.Item(0).Visible = False  ' make category 1 page not visible
                Forms!frm_Main!TabCtl0.Pages.Item(2).Visible = False  ' make category 3 page not visible
        
                Call UnselectOptionButtons
            
            Case Is = 3
            
                DoCmd.OpenForm "frm_Main"
                Forms!frm_Main!TabCtl0.Pages(2).SetFocus              ' set focus to Category 3 tab
                Forms!frm_Main!TabCtl0.Pages.Item(0).Visible = False  ' make category 1 page not visible
                Forms!frm_Main!TabCtl0.Pages.Item(1).Visible = False  ' make category 2 page not visible
                
                Call UnselectOptionButtons
    
            End Select

  4. #4
    Join Date
    Apr 2006
    Posts
    157
    try passing the id for the setfocus to a global variable
    then do your setfocus on the form's load event
    Only quitters quit!

  5. #5
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    setfocus to another not important object in the form before the hide statement.

    emiel

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In this type of situation I sometimes create a "phantom" textbox (named PhantomTextbox) that I shrink to the size of a pixel and us to setfocus to. I usually place it off in a corner somewhere, and the user doesn't even see it.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Apr 2006
    Posts
    157
    Make sure that you intialize all controls as visible first, then
    set the focus anywhere other than the control to hide, which of course you already ...

    It might be easier if you just disable the other tabs...
    Only quitters quit!

  8. #8
    Join Date
    Sep 2005
    Posts
    220
    How would I disable the other tabs? That's really what I would like to do.

  9. #9
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    This will keep your tab visible on the form but everything on the tabbed page is disabled:

    YourTabName.Enabled = False

    This actually makes the tab "disappear"

    YourTabName.Visible = False
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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