Link to home
Start Free TrialLog in
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.
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shadi Saleh
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial