如何在VBA中隐藏按钮控件

awo*_*gCM 8 ms-access onclick button access-vba

还有人在这里还在编程VBA吗?

我正试图让这段代码工作

Private Sub button3_click()

    'hide main buttons
    button1.Visible = False
    button2.Visible = False
    button3.Visible = False

    'show submenu buttons
    button4.Visible = True;
    button5.Visible = True;

End Sub
Run Code Online (Sandbox Code Playgroud)

我要做的基本上是我有一个主窗体,有5个主按钮控件.其中2个在启动时隐藏.因此,当我单击按钮3时,我想隐藏前3个主按钮,并"取消隐藏"其他两个按钮.尝试执行此事件时,出现错误

" 运行时错误2165 - 您无法隐藏具有焦点的控件 ".

以前有人遇到过这方面的编程吗?我确信这是可行的.我只是不明白这里出了什么问题......

Max*_*Max 7

在隐藏当前控件之前,将焦点更改为可见控件之一

Private Sub button3_click()

    'show submenu buttons
    button4.Visible = True
    button5.Visible = True

    DoEvents          'execute any pending events, to make sure the button 4 and 5 are really visible
    button4.SetFocus  'change the focus to a now visible control
    DoEvents          'execute any pending events, to make sure that button4 really has the focus

    'now you can hide the other buttons

    'hide main buttons
    button1.Visible = False
    button2.Visible = False
    button3.Visible = False

End Sub
Run Code Online (Sandbox Code Playgroud)

也许你可以跳过DoEvents命令,你应该试试