views:

242

answers:

1

I haven't searched real hard recently but in the past I have searched high and low to figure out a way to minimize the ribbon with VBA code. For me, most of my users have no use for the ribbon in Access, I would be very happy if I could reclaim the screen real estate for them.

I know I could train them to minimize it but...well...they are users, not computer geeks. :-)

+1  A: 

If your database is set up to display a particular form when it's opened, you could put this code in the form's open event:

Private Sub Form_Open(Cancel As Integer)
    Call HideRibbon
End Sub

Here is the HideRibbon sub:

Public Sub HideRibbon()
    'Access versions before 2007 did not have ribbon '
    'ignore error: '
    '2094, <App Name> can't find the toolbar 'Ribbon.'
    On Error Resume Next
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    On Error GoTo 0
End Sub

Edit: I changed the HideRibbon sub to eliminate On Error Resume Next. It does what I want in Access 2003 and 2007. Not sure about the string value returned by SysCmd(acSysCmdAccessVer) in all the earlier Access versions, or future Access versions.

Public Sub HideRibbon()
    'Access versions before 2007 did not have ribbon '
    If Val(SysCmd(acSysCmdAccessVer)) >= 12 Then
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
    End If
End Sub
HansUp
That did it, thanks
Icode4food
I think any use of On Error Resume Next is a programming error. I'd check the Access version instead, so you would only be executing the command if the version were 2007 or higher. I mean, you know exactly what the conditions are that produce the error and there's an infallible way to run a test that allows you to avoid producing the error. Also, if some error other than 2094 is generated, it will be ignored and you'll never know it.
David-W-Fenton
@David Thanks. The new HideRibbon sub is my attempt to address the issues you raised. Is that the "infallible way"?
HansUp
Well, I'm not sure it's infallible, but it's not going to run when it's inappropriate. And, of course, in future things could change and break it. I'd go with your second version, myself, though certainly a version with an error handler that ignores error 2094 would be the more "infallible," I guess. Anything that avoids On Error Resume Next is preferable, I'd say.
David-W-Fenton
The second version also avoids hiding a custom toolbar named Ribbon in an MDB running under A2003 or earlier. I like that behavior even though the scenario seems extremely unlikely.
HansUp