Anirudh Lou
Anirudh Lou

Reputation: 831

How to hide a Visible Object in MS Access?

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.

Upvotes: 0

Views: 653

Answers (2)

June7
June7

Reputation: 21370

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

Upvotes: 2

Anirudh Lou
Anirudh Lou

Reputation: 831

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

Upvotes: 0

Related Questions