Loop Through Detail Section Record Controls

M

Mike

Hi. I need to add an image to the detail section of a subform, and then
toggle it's Visibility based on another value in that particular record. The
loop I build to do this only seems to read the FIRST detail section record
(shown below). How can my loop read each record in the detail section?

Dim ctl As Control
For Each ctl In Me.Detail.Controls
If (ctl.Name = "imgPendingRenew") Then
ctl.Visible = RenewIsPending(Me.txtUniqueID)
End If
Next


Thanks!
 
A

Arvin Meyer MVP

Try using the recordsetclone of the subform. Your code, btw, only looks at
one record.
 
D

Dale_Fye via AccessMonster.com

1. If this is a continuous form, you are not going to be able to do this.
You cannot turn this on and off for individual records.
2. I'm not sure why you are looping through all the controls, when you know
the name of the control you want to set the visible property on.

Assuming this is not a continuous form, I think I would use the forms Current
event, something like:

Private sub form_Current

me.imgPendingRenew.Visible = RenewlsPending(me.txtUniqueID)

End sub
 
S

Stuart McCall

Mike said:
Hi. I need to add an image to the detail section of a subform, and then
toggle it's Visibility based on another value in that particular record.
The
loop I build to do this only seems to read the FIRST detail section record
(shown below). How can my loop read each record in the detail section?

Dim ctl As Control
For Each ctl In Me.Detail.Controls
If (ctl.Name = "imgPendingRenew") Then
ctl.Visible = RenewIsPending(Me.txtUniqueID)
End If
Next


Thanks!

This reference is the wrong syntax:

Me.Detail.Controls

It should be:

Me.Section(acDetail).Controls
 
M

Marshall Barton

Stuart said:
This reference is the wrong syntax:

Me.Detail.Controls

It should be:

Me.Section(acDetail).Controls


Stuart , if the detail section is named Detail (the default
name), then either syntax will work. There was a bug in
A2002 that kind of messed with some references tp an item in
a section's Controls collection, but For Each was fine.
 
S

Stuart McCall

Marshall Barton said:
Stuart , if the detail section is named Detail (the default
name), then either syntax will work. There was a bug in
A2002 that kind of messed with some references tp an item in
a section's Controls collection, but For Each was fine.

Maybe it was that bug which prompted me to always use the syntax I posted.
Can't remember.

Thanks for the clarification, Marsh.

To Mike: please just ignore my post.
 
M

Mike

Thanks all for your responses. This is a continuous form, so it doesn't
sound like this is possible.

Mike
 

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