Andrei Ion
Andrei Ion

Reputation: 1827

The name of a frame in a loop

I want to add a Control in every for in my application. Let's say I have 5 frames... I want to do someting like this:

Set cControl = Me!iooly&i.Controls.Add("Forms.Label.1", "str12" & i, True)
    With cControl
        .Caption = "1/2"
        .Width = 20
        .Height = 8
        .Top = 10
        .Left = 435
    End With

i is a counting variable the problems is that Me!iooly&i ... Can I do this operation when my frames have names la iooly1, iooly2, iooly3 and so on?

Upvotes: 2

Views: 198

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

Your Me is presumably a form? This won’t work. Also, the Me!iooly&i syntax doesn’t work, this only works if your string is a constant.

You can use the Forms collection though:

Set cControl = Forms("iooly" & i).Controls.Add(…)

This is assuming that the form already exists. If it doesn’t, you need to first load it.

Upvotes: 2

Related Questions