Home > OS >  How to hide a Visible Object in MS Access?
How to hide a Visible Object in MS Access?

Time:07-19

I have a button named btnSave that by default is not visible and when I clicked the button btnAdd, this is the time that btnSave showed. My aim is to make this button invisible again when I clicked it but I am getting this error:

Run-time error '2165':

You can't hide a control that has the focus.

This is how my code looks like:

Private Sub btnSave_Click()
   
   ....
   Me.Refresh
   Me.Repaint
   Me.btnSave.Visible = False
   Me.btnCancelSave.Visible = False

End Sub

Any help is much appreciated.

CodePudding user response:

The error message is clear - object cannot be set invisible while it has focus. Move focus elsewhere.

Me.someothercontrol.SetFocus
Me.btnSave.Visible = False
Me.btnSaveCancel.Visible = False

CodePudding user response:

After several googling this is what I found and thanks to the Author (Mike Wolfe). Here is the link: Fix for the error: "You can't hide a control that has the focus" in Microsoft Access

  • Related