Looping with subforms

  • Thread starter Thread starter Jeff
  • Start date Start date
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?
 
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.
 
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)
 
Back
Top