Is there anybody out here still programming VBA?
I'm trying to get this code to work
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
What I'm trying to do basically is that I have a main form that has 5 main button controls. 2 of them are hidden on startup. So when I click button 3, I want to hide the first 3 main buttons, and "unhide" the other two. When trying to execute this event, I got an error
"Runtime Error 2165 - You can't hide a control that has the focus".
Has anybody come across this aspect of programming before? I'm sure it's doable. I just don't understand what went wrong here...
Change the focus to one of the visible control, before hiding the current one
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
Maybe you can skip the DoEvents command, you should try
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With