We help IT Professionals succeed at work.
Get Started

MS Access: Sub Form Visibility Control

Last Modified: 2017-11-30
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.

Watch Question
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE