Make controls Visible or Not Visible (1 Viewer)

Sean75db

Registered User.
Local time
Today, 07:42
Joined
May 16, 2014
Messages
33
Hello,

I have a Main Form with a Sub-Form, the sub-form is base off a query. on the sub-form i have 8 controls, one of them is "Status' and "Process" and "Review"
My Main Form have a Refresh command that refreshes the data in the sub-form.

What i am trying to do is make the "Process" Control only visible is "Status" is a certain status and "Review" visible if "Status" is something else. what i have done works correctly On Open. I run into and issue on the refresh command. I get Run-time error '2165' "You can't hide a control that has the focus"

Code:
If Forms!Main_Form.[Name subform]!Status = "Ready" Then
        Forms!Main_Form.[Name subform]!Process.Visible = True
        Forms!Main_Form.[Name subform]!Review.Visible = False
ElseIf Forms!Main_Form.[Name subform]!Status = "Reviewing" Then
        Forms!Main_Form.[Name subform]!Review.Visible = True
        Forms!Main_Form.[Name subform]!Process.Visible = False
End If

Looking for suggestions or what i have done wrong or what i could try.
I have done similar with a main form and making sub-form visible or not based on a control on a main form and that has worked perfectly. I am not sure how the control is getting focus and cause the error.

Thanks
 

spikepl

Eledittingent Beliped
Local time
Today, 15:42
Joined
Nov 3, 2010
Messages
6,142
I am not sure how the control is getting focus and cause the error.

Who cares. The error message tells you quite specifically what to do and what not to do.

First set focus to one of the controls you are not going to hide and then make the rest invisible.
(setting focus in subforms is two-step thing - google set focus in subform )
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 14:42
Joined
Sep 12, 2006
Messages
15,715
I presume your cursor is on one of the process or review controls. you cannot hide a control that has the process. can you set the focus to a different control first?

differentcontrolname.setfocus
 

Sean75db

Registered User.
Local time
Today, 07:42
Joined
May 16, 2014
Messages
33
Thanks, yes I realized my issue a minute after I posted. I had tryed to set the focus to something else. I just needed to set the focus to the control that is visible.
 

spikepl

Eledittingent Beliped
Local time
Today, 15:42
Joined
Nov 3, 2010
Messages
6,142
Hehe been there done that: typing the post clarifies one's mind :D
 

Users who are viewing this thread

Top Bottom