Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Hmm.. might've spoken too soon.. I think I just had a breakthrough. I just realized that I didn't have a tag assigned to the FormHeader or FormFooter in any of these 3 forms. I guess I wasn't thinking of those as controls.


    The FormHeader is most likely the "control that has the focus" that the error kept referring to.

    EDIT - nevermind.. that wasn't it.

  2. #17
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    My code that you are using should be placed in a standard module - NOT in individual forms
    It is designed to apply to the ACTIVE form at any time
    Even if you have multiple forms open at once, only one can be ACTIVE at any time

    If you adapt it as described, you are making unnecessary extra work for yourself
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #18
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    I realize that, but it's the only way that seems to get around the error message that crops up on the Form_Load event.
    If I change the line, "For Each Ctrl in Screen.ActiveForm.Controls" to "For Each Ctrl In frm.MyForm1" - without changing any of the subsequent code - then the form loads properly.
    If I don't update the code to point specifically to that form (instead of simply referencing Active Form as its intended) it produces an error message which states, "You can't hide a control that has the focus".

  4. #19
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Quote Originally Posted by Bcanfield83 View Post
    I realize that, but it's the only way that seems to get around the error message that crops up on the Form_Load event.
    If I change the line, "For Each Ctrl in Screen.ActiveForm.Controls" to "For Each Ctrl In frm.MyForm1" - without changing any of the subsequent code - then the form loads properly.
    If I don't update the code to point specifically to that form (instead of simply referencing Active Form as its intended) it produces an error message which states, "You can't hide a control that has the focus".
    OK that's a separate issue. Open your form in design view.
    Click Tab order in the Design ribbon. Look at the first item in the order for each section of the form
    You are trying to hide one of the controls that are first in the list.
    Either change the tag value for that control so it stays visible at first or change the order so one of the controls that stays visible is first
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #20
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Quote Originally Posted by ridders52 View Post
    OK that's a separate issue. Open your form in design view.
    Click Tab order in the Design ribbon. Look at the first item in the order for each section of the form
    You are trying to hide one of the controls that are first in the list.
    Either change the tag value for that control so it stays visible at first or change the order so one of the controls that stays visible is first
    First off - thank you, I had no idea about checking "Tab Order".
    I'm still a bit perplexed though because the first item in each section ("Form Header", "Detail", and "Form Footer") is tagged with "Default" - which is the tag that's being set to Visible in the Form_Load event.
    Yet I'm still receiving the error message "Error 2165 - You can't hide a control that has the focus" when I click to open up the form.

    The only thing I can think of is that that the error message is actually referring to something in the Main Menu of my database? There's a button on the Main Menu that opens up this particular form (as well as a couple others that produce the same error message).
    Because if I simply tweak your code ("ShowControls") so that it only applies to this 1 specific form - as opposed to stating "For Each Ctrl in Screen.ActiveForm.Controls" - then oddly it works as intended. I also noticed that when it's referring to Screen.ActiveForm.Controls, a couple of the controls in my Main Menu Form are suddenly visible. But as far as the Main Menu Form is concerned, I haven't tagged *any* of the controls on it. In theory, the code should only be applied to a form in which the "Tag" property is being used (on 1 or more controls in that form), correct?
    Code:
    ShowControls True, "Default"
    ShowControls False, "Hidden", "Completed"

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Your final sentence is correct.

    Not sure how to advise with regard to your current issue.
    I've used the code in numerous apps and its been downloaded and used many times from various forums.

    Clearly it's trying to hide something which has the focus but I can't tell what without looking at it.

    Perhaps it would be worthwhile you posting a stripped down copy of your app.
    Remove all items not relevant to this issue and most of the data including anything confidential.
    If you can do that I'll see if I can solve your problem
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #22
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Thanks - my temporary workaround, as ridiculous and stupid as it is, involves commenting out the ErrHandler lines in the "ShowControls" sub. 'Cause the forms look perfectly fine when they open up - the controls that I'm intending to display are visible, and the ones that I don't want to display are hidden.


    Code:
    On Error GoTo Err_Handler
    Code:
    Err_Handler:
        MsgBox "Error " & Err.Number & " " & Err.Description
        Resume Exit_Handler

  8. #23
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Quote Originally Posted by Bcanfield83 View Post
    Thanks - my temporary workaround, as ridiculous and stupid as it is, involves commenting out the ErrHandler lines in the "ShowControls" sub. 'Cause the forms look perfectly fine when they open up - the controls that I'm intending to display are visible, and the ones that I don't want to display are hidden.


    Code:
    On Error GoTo Err_Handler
    Code:
    Err_Handler:
        MsgBox "Error " & Err.Number & " " & Err.Description
        Resume Exit_Handler
    Its NEVER a good idea to remove all error handling other than in testing
    Whilst it may work for now, any errors later will lead to unpredictable results

    If you must bypass this issue, then this would be better as only err 2165 is bypassed

    Code:
    Err_Handler:    
        If err=2165 Then Resume Next
    
        MsgBox "Error " & Err.Number & " " & Err.Description
        Resume Exit_Handler
    
    End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Hide text boxes when Report Footer displays
    By Paul H in forum Reports
    Replies: 3
    Last Post: 12-01-2017, 05:05 PM
  2. Replies: 3
    Last Post: 11-22-2015, 11:01 AM
  3. Info from queries in text boxes
    By Desmondo in forum Programming
    Replies: 4
    Last Post: 08-29-2015, 10:38 PM
  4. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  5. Replies: 5
    Last Post: 09-02-2011, 03:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums