Setting checkbox value in subform

A

Andrew Glennie

Hi All,

I am wanting to set the value of a checkbox on each line of a subform based
on a value on the main form and a value on the subform. the code I hoped
would work is below. Clearly it doesn't as the checkbox I'm wanting to set is
always set to True irrespective of the value of the other subform checkbox.

Private Sub Form_Current()

If Forms![Events]![EventTypeID].Value = 1 And Forms![Events]![Events
Subform].Form![L2 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
ElseIf Forms![Events]![EventTypeID].Value = 2 And Forms![Events]![Events
Subform].Form![L4 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
End If

End Sub

So what am I doing wrong? TIA.

Andrew
 
M

Minton M

Hi All,

I am wanting to set the value of a checkbox on each line of a subform based
on a value on the main form and a value on the subform. the code I hoped
would work is below. Clearly it doesn't as the checkbox I'm wanting to set is
always set to True irrespective of the value of the other subform checkbox.

Private Sub Form_Current()

If Forms![Events]![EventTypeID].Value = 1 And Forms![Events]![Events
Subform].Form![L2 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
ElseIf Forms![Events]![EventTypeID].Value = 2 And Forms![Events]![Events
Subform].Form![L4 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
End If

End Sub

So what am I doing wrong? TIA.

Andrew

Yeah, but subforms don't allow independent unbound controls. Any
unbound controls will all exhibit the same behavior (ie. you check one
checkbox and they all get checked). There are *painful* ways to make
it work, but my advice would be to look at using a listbox instead
since most implementations of this idea work well with listboxes.

I hope this helps,
James
 
A

Andrew Glennie

Thanks James

Listbox won't do what I am looking for so I will look to another method.

Thanks

Andrew
Minton M said:
Hi All,

I am wanting to set the value of a checkbox on each line of a subform based
on a value on the main form and a value on the subform. the code I hoped
would work is below. Clearly it doesn't as the checkbox I'm wanting to set is
always set to True irrespective of the value of the other subform checkbox.

Private Sub Form_Current()

If Forms![Events]![EventTypeID].Value = 1 And Forms![Events]![Events
Subform].Form![L2 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
ElseIf Forms![Events]![EventTypeID].Value = 2 And Forms![Events]![Events
Subform].Form![L4 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
End If

End Sub

So what am I doing wrong? TIA.

Andrew

Yeah, but subforms don't allow independent unbound controls. Any
unbound controls will all exhibit the same behavior (ie. you check one
checkbox and they all get checked). There are *painful* ways to make
it work, but my advice would be to look at using a listbox instead
since most implementations of this idea work well with listboxes.

I hope this helps,
James
 
A

Andrew Glennie

Hi James,

A much simpler solution which is working - take the L2 Attended and L4
Attended checkboxes, lay them one on top of the other, and turn them on or
off depending on the EventTypeID value. Works like a dream:)

regards

Andrew

Minton M said:
Hi All,

I am wanting to set the value of a checkbox on each line of a subform based
on a value on the main form and a value on the subform. the code I hoped
would work is below. Clearly it doesn't as the checkbox I'm wanting to set is
always set to True irrespective of the value of the other subform checkbox.

Private Sub Form_Current()

If Forms![Events]![EventTypeID].Value = 1 And Forms![Events]![Events
Subform].Form![L2 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
ElseIf Forms![Events]![EventTypeID].Value = 2 And Forms![Events]![Events
Subform].Form![L4 Attended].Value = True Then
Forms![Events]![Events Subform].Form![Attended].Value = True
End If

End Sub

So what am I doing wrong? TIA.

Andrew

Yeah, but subforms don't allow independent unbound controls. Any
unbound controls will all exhibit the same behavior (ie. you check one
checkbox and they all get checked). There are *painful* ways to make
it work, but my advice would be to look at using a listbox instead
since most implementations of this idea work well with listboxes.

I hope this helps,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top