Results 1 to 8 of 8
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    MS Access / VBA - Test if Ribbon/toolbars are hidden

    Hi all, new to the forum!



    I did some digging, but can't seem to figure out how to test if the ribbon is visible. I've tried testing the height of the command bar, but can't get that to work.

    Whats the best approach here? Basically, i'd like to test if these conditions are true....

    Code:
    Sub hideToolbars()
    
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    DoCmd.SelectObject acForm, , True
    DoCmd.RunCommand acCmdWindowHide
    
    
    End Sub
    
    
    Sub unhideToolbars()
    
    
    DoCmd.ShowToolbar "Ribbon", acToolbarYes
    DoCmd.SelectObject acForm, , True
    End Sub

    Thanks for your time.

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    I think it's something like...

    Code:
    If Application.CommandBars("Ribbon").Height > 100 Then

  3. #3
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Quote Originally Posted by GinaWhipp View Post
    I think it's something like...

    Code:
    If Application.CommandBars("Ribbon").Height > 100 Then
    GinaWhipp, thanks for your reply.

    This method still does not function properly for toggling on/off hide/show

    Button Click Event:
    Code:
    Private Sub bhideshow_click()
    
    If Application.CommandBars("Ribbon").Height > 100 Then
    
         Call hideToolbars
    
    Else
        Call unhideToolbars
    End If
    
    End Sub
    Hide / show Sub:

    Code:
    Sub hideToolbars()
    
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    DoCmd.SelectObject acForm, , True
    DoCmd.RunCommand acCmdWindowHide
    
    
    End Sub
    
    
    Sub unhideToolbars()
    
    
    DoCmd.ShowToolbar "Ribbon", acToolbarYes
    DoCmd.SelectObject acForm, , True
    
    
    End Sub

  4. #4
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, perhaps you need to first determine if it's showing, so...

    Code:
    If Application.CommandBars("Ribbon").Height > 100 = True Then
         Call hideToolbars
    Else
         Call unhideToolbars
    End If
    Also, where are you putting the code?

  5. #5
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Hi,

    The button click event on a form triggers the test i am trying to do.

    The hidetoolbars/unhidetoolbars is in a module. Those subs work, just not when verifying this test. I've got the test to pass in some cases, but toggling does not work.

    Thanks

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    Try adding these functions to your module

    Code:
    Public Function ToggleRibbonState()
    'hide ribbon if visible & vice versa
        CommandBars.ExecuteMso "MinimizeRibbon"
    End Function
    
    Public Function IsRibbonMinimized() As Boolean
        'Result: 0=normal (maximized), -1=autohide (minimized)
        IsRibbonMinimized = (CommandBars("Ribbon").Controls(1).Height < 100)
       ' Debug.Print IsRibbonMinimized
    End Function
    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. #7
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Hello ridders,

    Just now getting back to this issue...

    Your code works fine for the ribbon, but when supplementing with my hidetoolbars code, it does not work. And i think this is because I am hiding the command bar too so the test does nothing because there is no ribbon.



    Code:
    Sub hideToolbars()
    
    
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    DoCmd.SelectObject acForm, , True
    DoCmd.RunCommand acCmdWindowHide
    
    
    End Sub
    
    
    Sub unhideToolbars()
    
    
    DoCmd.ShowToolbar "Ribbon", acToolbarYes
    DoCmd.SelectObject acForm, , True
    End Sub
    
    
    
    
    
    
    Public Sub ToggleRibbonState()
    'hide ribbon if visible & vice versa
        If IsRibbonMinimized = True Then
            Call unhideToolbars
        Else
            Call hideToolbars
        End If
        
        
        'CommandBars.ExecuteMso "MinimizeRibbon"
    End Sub
    
    
    Public Function IsRibbonMinimized() As Boolean
        'Result: 0=normal (maximized), -1=autohide (minimized)
        IsRibbonMinimized = (CommandBars("Ribbon").Controls(1).Height < 100)
       ' Debug.Print IsRibbonMinimized
    End Function

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    See if my example database helps http://www.mendipdatasystems.co.uk/c...ace/4594365418

    If not then suggest you post a stripped down copy of your database
    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

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-04-2014, 09:05 PM
  2. Replies: 2
    Last Post: 04-19-2013, 07:07 PM
  3. Custom VBA Toolbars (Access 2003, XP)
    By DenisStarbank in forum Access
    Replies: 0
    Last Post: 03-28-2013, 04:55 PM
  4. Replies: 0
    Last Post: 01-18-2011, 07:09 AM
  5. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 AM

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