Avatar of Shadi Saleh
Shadi Saleh
 asked on

MS Access: Sub Form Visibility Control

I have a main form ("MF") with a big number of controls on it including one sub form. This sub form named "SF" and is related with two of the controls in the main form named "C1" and "C2".

When form is loaded SF is not visible.

When C1 or C2 got focus SF visibility set to True.

Now what I need is to set SF visibility to False if  C1 or C2 lost focus, but the new focused control is not SF.

It seemed simple at the begining and it seemed straight forward, but it is not.

I used

Private Sub C1_GotFocus()
    Me.SF.Visible = True
End Sub

Private Sub C2_GotFocus()
    Me.SF.Visible = True
End Sub

Private Sub C1_LostFocus()
    Me.SF.Visible = False
End Sub

Private Sub C2_LostFocus()
    Me.SF.Visible = False
End Sub

This works great for all controls on the MF (Main Form).

The problem is that applies  SF(Sun Form) too while I want to work on it.

SF is a list that I can pick a value from it and put it in the C1 or C2.

Now as SF disappears after C1 or C2 loses control, I cannot pick anything.

a workaround would be to omit the lost focus events for C1 and C2 and setting every other single control on the main form get focus control to hide SF.

While this works as I need. It seems not to be a good solution.

Is there a more straight forward way to accomplish this?

Remember Main form controls are too many too be coded this way.

Thanks.
Microsoft Access* Losing focus

Avatar of undefined
Last Comment
Dale Fye

8/22/2022 - Mon
SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shadi Saleh

ASKER
Thanks LVL49 and LVL85,

Please not that I want to avoid using Get Focus event for all controls. it does not seem to be the right way to do it. I stated in the question that I can do it but I need a different solution :)

Thank you for your contribution anyway.
SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes