Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Box in 1 Subform Make Another Subform Visible 3

Status
Not open for further replies.

cstuart79

Technical User
Nov 2, 2009
171
US

I am wondering if there is a way to open a subform when check box in a different subform is clicked and close when check box is unmarked (want to keep them visually separate)

Here are the specifics:
I have a "MasterKey" subform that consists of a list of items with check boxes. The "MasterKey" is tied to a larger client list by field "clientorderid".

I then have different subforms that correspond to each of the fields on the "MasterKey". Each of these subforms is tied to the larger client list by field "clientorderid". One such subform is "Sessions" which corresponds to the field "FIXSessions" on subform "MasterKey".

What I am trying to do is synch the various subforms to the subform "MasterKey" so that when I check one of the boxes (eg. "FIXSessions") another subform will become visible (eg. "Sessions" will appear).
 
You can use the after update event of a check box on a subform to hide or display another subform on the main form with code like:
Code:
    Me.Parent.Sessions.Visible = Me.FIXSessions = True
This displaying and hiding is triggered only by the act of checking or unchecking the checkbox.

Duane
Hook'D on Access
MS Access MVP
 

Something like this?
Code:
Private Sub Check2_Click()
    Me.frmInput.Visible = Me.Check2
End Sub


Randy
 
Thanks for your suggestions; however, I keep getting the following error since it does not seem to allow me to input the main form (parent). Or should it be something else since the commonality between all subforms and main form is the field "Client ID"?


Run-time error '2452':
The expression you entered has an invalid reference to the Parent property.


This is what I have attempted to enter:

Private Sub chkDirect_Connect_Click()
Me.Client.DIRECT_CONNECT.Visible = Me.chkDirect_Connect = True
End Sub
 
yes, they are all embedded on the same main form "Clients
 
I assume the code is running in the subform. Also, do you understand the difference between a subform control name and its Source Object? You need to reference the [control name].visible, not the name of the source object.

What is you complete code? If the code is running in the subform, the parent property is legitimate.

Duane
Hook'D on Access
MS Access MVP
 
cstuart79 . . .

The parent to Me.FIXSessions is the subform its on. Clients is the parent to this form. Note two parents cited, so try:

Code:
[blue]   Me.Parent.Parent.Sessions.Visible = Me.FIXSessions = True[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
This is how I assume the forms and subforms are set up. Please let us know if this is not correct (diregard the positioning)
[tt][blue]
+--main form-------------------------------------+
| |
| +MasterKey--+ +--Sessions--------+ |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| +-----------+ +------------------+ |
| |
| |
+------------------------------------------------+
[/blue][/tt]




Duane
Hook'D on Access
MS Access MVP
 
-Main form is "Clients"
-Subform embedded on "Clients" is "Master_Key" (this contains check boxes to open up other subforms); Record Source is "Master_Key" table
-Subform embedded on "Clients" is "Direct_Connect" (this is one such subform that I want to make visible/hidden based upon check box); Record Source is "Direct_Connect" table
-Check box in Detail of "Master_Key" is "chkDirect_Connect" with Control Source of "Direct_Connect" field (located in Master_Key table)

In the check box "chkDirect_Connect" I have added the code to On Click Events:

Private Sub chkDirect_Connect_Click()
Me.Clients.DIRECT_CONNECT.Visible = Me.chkDirect_Connect = True
End Sub
 
These is not a Me.Clients. This should be referenced as Me.Parent.
Code:
Private Sub chkDirect_Connect_Click()
    Me.Parent.DIRECT_CONNECT.Visible = Me.chkDirect_Connect = True
End Sub
When you state [red]Subform embedded on "Clients" is "Direct_Connect"[/red] are you referring to the Source object or Name of the subform control?

Again, are you ok with the hiding and displaying only changing when the check boxes are actually clicked?

Duane
Hook'D on Access
MS Access MVP
 
Worked perfectly!
However, now i have a different problem.
When i uncheck the Direct Connect check box it disappears on "Client A" as it is supposed to, but it also disappears on "Client B, C, D, etc.". I want to be able to check/uncheck for each client uniquely.

The main form has a List Box with all clients (A, B, C, D, etc.) which allows for one to be selected and unique info to be viewed.
 
That's why I have asked twice
Duane said:
Again, are you ok with the hiding and displaying only changing when the check boxes are actually clicked?

You will need to run the code to hide or display the subforms in the On Current event of the Master_Key subform.

Duane
Hook'D on Access
MS Access MVP
 
sorry i didn't understand what you were asking at first.
i added the same code to On Current event of the Master_Key subform but it still continues to affect all clients on my List Box.
 
When you select a client in the list box, isn't the Master_Key subform viewing the appropriate client? Isn't the view or hide determined by values in the Master_Key subform?

Maybe you need to describe the record sources and fields again.

Duane
Hook'D on Access
MS Access MVP
 
yes it is viewing the appropriate client, and the view or hide should be determined by values in Master_Key subform. I added same code to After Update and On Exit events as well and it seems to work now. However, I do keep getting the Run-time error 2452:

The expression you entered has an invalid reference to the Parent property.

I'm wondering if I need to change something in the Master/Child links to correct this??
 
Figured it out--had a mismatch in naming of fields. Thank you so much for all of your help!! I truly appreciate it.
 
here's my two cents.
You probably need to refer to the main form/ subform explicitly. I often need do this in subforms when I want to pass data either to a main form or another subform.
I didn't read the entire post so...
Code:
Private Sub Check35_Click()
    'if the subform is on a main form
    Forms![Mainform Name]![Subform Name].Visible
    
End Sub
I also use the QBE qrid, and use it's "Build..." option (right click in the criteria grid) then let Access make the correct syntax. then I copy and paste what it make's in my VBA code. the build as you old guys know used to be part of the Access in version 2 or 95 before VBA became a separate program.

here is one I'm doing now...
I want to set txtReportName a text box on the main form to [Project Number] on the sub form when a record in the subform is clicked.
Code:
Private Sub Form_Click()
[Forms]![frmIH]![txtReportName]=[Forms]![frmIH]![IH-Results subform3].[Form]![Project Number]
    
End Sub

Anyway hope this helps


DougP
[r2d2] < I Built one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top