wizard_draziw
wizard_draziw

Reputation: 515

How do I reference a Subform with a Variable?

I'm trying to reference a subform's properties by a variable so that I can loop through different subform names. Through much google-fu I think i'm close but it keeps saying it can't find the field "Controls".

  f = "[TerritoryCode] = """ & tcode & """"
  strsubform = "subDM" & loopnumber
  Me!Controls(strsubform).Form.Filter = f
  Me!Controls(strsubform).Form.FilterOn = True

So strsubform should keep producing something like "subDM1", "subDM2", etc, and then it's going to filter via the variable f. This works just fine if I directly reference subDM1, but that's no fun.

Thanks!

Upvotes: 1

Views: 2081

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123409

In this case "Bang notation" (foo!thing) refers to the value of a Field in the Form (i.e., the Recordset of the Form), while "dot notation" (foo.thing) always refers to Properties, Methods, and Collections belonging to an object. So,

Me!Controls

equates to

Me.Fields("Controls").Value

but Controls is a Collection of Control objects, not a field name. Therefore we need to use

Me.Controls

Upvotes: 1

Related Questions