Checkboxes on subforms

  • Thread starter Thread starter htmldiva
  • Start date Start date
H

htmldiva

I have a form for all my clients. On that form, there is a subform fo
all client matters. On my client form, I have a checkbox for inactiv
clients. On my subform I also have a checkbox for inactive matters.

When I check the inactive checkbox on my client form, I would also lik
the checkbox on the subform for all client matters to be checked.

Need help with the code. Thank
 
In the OnClick event of the check box on the client form, put:

Me.Form.MattersSubform.Form.cbInactiveMatter = Me.Form.cbInactiveClient

Replace the names with the ones you actually have.
Cheers,
Pavel
 
Thank you Pavel for your prompt response. When I check the clien
checkbox, it checks the subform checkbox, but only the first one. Tha
will work when I have one client with one matter, but when I have on
client with several matters it doesn't. How do I get all matters unde
the same client to be checked
 
htmldiva said:
I have a form for all my clients. On that form, there is a subform for
all client matters. On my client form, I have a checkbox for inactive
clients. On my subform I also have a checkbox for inactive matters.

When I check the inactive checkbox on my client form, I would also like
the checkbox on the subform for all client matters to be checked.

Need help with the code. Thanks

Something like this goes into the code for your form

Private Sub inactiveClientsCheckBox_AfterUpdate()
If Me.inactiveClientsCheckBox then
UpdateClientsInactiveMatters Me.ClientNum , True
Else
UpdateClientsInactiveMatters Me.ClientNum , False
End if
Me.Refresh
End If
End Sub

Public Sub UpdateClientsInactiveMatters (TheClientNum As Long, TheFlag As
Boolean)
Dim dbs As ADODB.Connection, strSQL As String
' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the database

strSQL = "UPDATE [tblClientMatters] SET [InactiveMatters] = " & TheFlag
& " WHERE [ClientNum ] = " & TheClientNum

dbs.Execute strSQL ' run the query
Set dbs = Nothing
End Sub
 
I have a form for all my clients. On that form, there is a subform for
all client matters. On my client form, I have a checkbox for inactive
clients. On my subform I also have a checkbox for inactive matters.

When I check the inactive checkbox on my client form, I would also like
the checkbox on the subform for all client matters to be checked.

Need help with the code. Thanks

No code should be needed. You should simply use the checkbox field in the main
form to identify that the client is inactive and lose the checkbox in the child
records. If you include the parent record's "inactive" field with the child
records (the included tables joined on the key field) in any queries, it will be
as if the field existed in the child records.
 
I couldn't get your sample DB from the URL you sent.
I think I'd use SQL to accomplish this. It is more efficient than using
recordsets in VBA. Have you tried the solution Treebeard recommended?
If you insist on doing it in VBA:

With Me.Form.MattersSubform.Form.Recordset
..MoveFirst
while not .EOF do
.Fields("ClientMatter") = Me.Form.cbInactiveClient
.MoveNext
wend
..Refresh
end with

Hope this works.
Pavel
 
I still can't get it to work. I created a sample database for practice.
The file (which is small) is attached. I want each checkbox on the
subform to be selected when I select the checkbox on the main form.

As long as the "active" status is defined in the Client's record, the additional
effort you are going to is superfluous. You are expending all this effort to
fool with redundant data. Did you not understand my previous post?
 
Thank you all, especially Pavel. I'll admit. I'm not as comfortabl
with SQL as I am with VB. Here's the final code that I added to th
main checkbox's After Update event. It works like a charm:

Private Sub Private_AfterUpdate()
If Me.Form.Private = True Then
With Me.Form.Contactssubform.Form.Recordset
.MoveFirst
Me.Contactssubform.Form.Private = True
Do Until .EOF
.MoveNext
Me.Contactssubform.Form.Private = True
Loop
End With
End If
End Su
 
Back
Top