Looping with subforms

J

Jeff

How do I write a reference to names of subforms.
I have 5 subforms that I want to reference using a do loop
This is what I have tried
Example:
Grid1 thru Grid5 are subforms


Dim varGridNumber As Variant
Dim counter as Variant
counter = 1

do
VarGridNumber = "grid" & counter
Me.varGridNumber.SourceObject = varGridNumber
counter = counter +1
do until counter = 5

The error is "Method or data member not found"
What is the problem?
 
A

Allen Browne

Try:
Me(varGridNumber).SourceObject = varGridNumber

If that still fails, double-check that the Name of each subform control is
in fact the same as its SourceObject. It ma not be.

BTW, it may be better to use a String variable for varGridNumber.
 
J

Jeff

Allen, Thanks for the reply. This works great!
This brings me to another problem. In this same loop I am updating a label
that is on the subforms.
The error is: "The expression you entered refers to an object that is closed
or dosnt exist"

Me(varGridNumber).Form(varGridNumberlbl).Caption = Day(varGridNumberDate)
 

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