variable names to objects

  • Thread starter Thread starter Kicker
  • Start date Start date
K

Kicker

Guest
Depending on what data is contained in a table field, I want to reference different controls on my form. for example:

I have a userForm with the associated userTable. One of the fields in userTable is ControlName. For simplicity sake, lets say the field contents are "Label1", "Label2", etc. It could verywell be "Button1", "Button2", etc.

If I use a command button to run a sub, it the following code works:

[userform].[Label1].[text] = "This is a test"

However, since the userTable contains the "Label1" as the data from the ControlName field. How do I use the field contents?

[userForm].[me.recordset!ControlName].[text] = "This is a test"

I have tried just about every combination I can think of.

ttfn
Kicker
 
Kicker,

Me.Controls(me.recordset!ControlName) = "This is a test"

Wayne
 
Thanks Wayne:

Ok, how would I call all of the properties of the control?

Me.Controls(me.recordset!ControlName).caption = "This is a test"
Me.Controls(me.recordset!ControlName).backcolor = vbred
Me.Controls(me.recordset!ControlName).top = 1500
Me.Controls(me.recordset!ControlName).left = 2400

etc?

I am getting close to what I need and can almost "taste" it.

ttfn
Kicker
 
Kicker,

You got it!

If you name them "appropriately", you can loop through them calling them
something like: Me.Controls("SomeText" & CStr(i))

But, I think you're storing their names in a table.

Will look for your results!

Wayne
 
it works..... Thanks Wayne

Code:
Private Sub Command0_Click()
Dim vCount As Long
Dim n As Long

    Me.Recordset.MoveFirst
    vCount = Me.Recordset.RecordCount
    For n = 1 To vCount
        Me.Controls(Me.Recordset!LabelNum).Left = Me.Recordset!XAxis
        Me.Controls(Me.Recordset!LabelNum).Top = Me.Recordset!YAxis
        Me.Controls(Me.Recordset!LabelNum).Caption = Me.Recordset!SSRNum
        Me.Recordset.MoveNext
    Next n
End Sub

I will end up making some minor changes, but this seems to work. Next thing is to create 30+ labels and make the .visible property FALSE. Then, When needed, make them visible and place them where they need to go.

ttfn
Kicker
 
Kicker,

Glad to hear it!

Remember when you make them, give them names so that you can
loop through them. You might to need to do something to all of them.

1) Either use the Me.Controls("SomeConstant" & CStr(i))

or

2) Traverse a recordset and use their meaningful names.

Wayne
 
since their usage will be helter skelter and their dates will overlap a lot, I am going to loop through a table and use their actual names such as Label1, Label2, etc. That is a "just because" and for no other real reason. Label2 might be used for 2 months straight and label 1 might expire in 4 days while Label 1 might be used again next week for another project.

What I am doing is creating a local table to relate to multiple linked tables. Through a query, I can select all of the "active" projects and plot them on a map of the area. Then when new projects crop up via active dates, I can automatically see them, move their label to mark their location. Then, when a supervisor or manager looks at the map, he/she will see where the workload is centered. Then, when the work completes, the date/time will prevent the label from being shown and make it available for the next work window.

Right now, I am about half way there. The rest is mostly grunt work and putting all the pieces together.

I appreciate your help. I would be happy to post the results, but the "data" is in a linked Oracle database and the map is somewhat sensitive. But I could fudge something up. Just might be something someone can use elsewhere.

ttfn
Kicker
 

Users who are viewing this thread

Back
Top Bottom