vba MSAccess - 最小化工具栏功能区 OnLoad()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18240240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:25:38  来源:igfitidea点击:

MSAccess - Minimize the Toolbar Ribbon OnLoad()?

vbams-access

提问by Mark Pelletier

I'm looking for a reliable method to minimize the default MSAccess Toolbar Ribbon during the OnLoad() event.

我正在寻找一种可靠的方法来最小化 OnLoad() 事件期间的默认 MSAccess 工具栏功能区。

I realize can totally HIDE the toolbar, but that's not exactly what I am looking to do - I just want to minimize the ribbon:

我意识到可以完全隐藏工具栏,但这并不是我想要做的 - 我只想最小化功能区:

DoCmd.ShowToolbar "Ribbon", acToolbarNo    'Hides the full toolbar
DoCmd.ShowToolbar "Ribbon", acToolbarYes   'Show

I've tried a couple approaches, with mixed success:

我尝试了几种方法,但成功不一:

In Access 2010 & 2013 (VB7):

在 Access 2010 和 2013 (VB7) 中:

CommandBars.ExecuteMso "MinimizeRibbon"

Earlier Versions:

早期版本:

SendKeys "^{F1}", False

Both of these approaches appear to operate as a TOGGLE between sessions. Is there a method to determine the current state and then apply the appropriate code?

这两种方法似乎都作为会话之间的切换操作。有没有一种方法可以确定当前状态,然后应用适当的代码?

I have users with Access: 2007, 2010, 2013

我有访问权限的用户:2007、2010、2013

Thanks for any suggestions!

感谢您的任何建议!

Mark

标记

采纳答案by Elias

Check out this answer on MSDN. He shares a few different ways to go about it, including a sample database.

在 MSDN 上查看此答案。他分享了几种不同的方法,包括示例数据库。

E.G. In Access 2010 you can change the Ribbon state with:

EG 在 Access 2010 中,您可以通过以下方式更改功能区状态:

CommandBars.ExecuteMso "MinimizeRibbon"

http://social.msdn.microsoft.com/Forums/office/en-US/2f0d95a8-ed5f-4007-831d-05ef7e7a4263/minimize-the-ribbon-at-access-startup-using-vba

http://social.msdn.microsoft.com/Forums/office/en-US/2f0d95a8-ed5f-4007-831d-05ef7e7a4263/minimize-the-ribbon-at-access-startup-using-vba

He links within:

他链接到:

http://www.accessribbon.de/en/index.php?FAQ:19

http://www.accessribbon.de/en/index.php?FAQ:19

http://www.accessribbon.de/en/index.php?Downloads:15

http://www.accessribbon.de/en/index.php?Downloads:15

Based on what access is being used, you could use different functions, perhaps.

根据正在使用的访问权限,您也许可以使用不同的功能。

Taking this from - http://windowssecrets.com/forums/showthread.php/142262-How-to-find-Access-version-in-code:

取自 - http://windowssecrets.com/forums/showthread.php/142262-How-to-find-Access-version-in-code

Public Function AccessVersionID() As String


   Select Case SysCmd(acSysCmdAccessVer)
     Case 7: AccessVersionID = "95"
     Case 8: AccessVersionID = "97"
     Case 9: AccessVersionID = "2000"
     Case 10: AccessVersionID = "2002"
     Case 11: AccessVersionID = "2003"
     Case 12: AccessVersionID = "2007"
     Case 13: AccessVersionID = "Pirated!"
     Case 14: AccessVersionID = "2010"
     Case 15: AccessVersionID = "2013"
     Case Else: AccessVersionID = "Unknown"
   End Select

 End Function            'AccessVersionID()

回答by Dave Stuart

Access 2010 version and up you should do this in your start-up form. If you just use the ExecuteMso line ONLY it will TOGGLE your Ribbon each time that form opens. To always minimize the Ribbon on Startup then I use the following code.

Access 2010 及更高版本,您应该在启动表单中执行此操作。如果您只使用 ExecuteMso 行,它会在每次打开该表单时切换您的功能区。为了始终最小化启动时的功能区,我使用以下代码。

If CommandBars("ribbon").Height > 100 Then
    CommandBars.ExecuteMso "MinimizeRibbon"
End If

Hope this Helps some who is looking for the answer to this like myself

希望这可以帮助一些像我这样正在寻找答案的人

Dave

戴夫

回答by Mark Pelletier

Here's a snippet of my implementaion:

这是我的实现的一个片段:

Select Case SysCmd(acSysCmdAccessVer)
    Case 7: accVer = "95"
    Case 8: accVer = "97"
    Case 9: accVer = "2000"
    Case 10: accVer = "2002"
    Case 11: accVer = "2003"
    Case 12: accVer = "2007"
    Case 13: accVer = "Pirated!"
    Case 14: accVer = "2010"
    Case 15: accVer = "2013"
    Case Else: accVer = "Unknown"
End Select

RibbonState = (CommandBars("Ribbon").Controls(1).Height < 100)

Select Case RibbonState
    Case True
        'Do nothing, already minimized
    Case False
        If accVer > 13 Then
            CommandBars.ExecuteMso "MinimizeRibbon"
        Else
            SendKeys "^{F1}", False
        End If
End Select

回答by Danage

Just moved to Access 2016. My database uses similar code to that provided by Dave Stuart. Looks like minimized ribbon now has height of '102', so have used (e.g.):

刚刚转移到 Access 2016。我的数据库使用与 Dave Stuart 提供的代码类似的代码。看起来最小化的功能区现在的高度为“102”,所以使用了(例如):

If CommandBars("ribbon").Height > 120 Then
  CommandBars.ExecuteMso "MinimizeRibbon"
End If