calculated textual reference to form object

G

Guest

NOTE: some statements in following code commented out to show other avenues
explored and rejected on failure

How do I directly reference a form object through indirect textual
calculated methods???

suppose I have form objects... L01,L02,L03...L09,L10 (in this case checkbox
labels)
I want to set the captions via a lookup @ form open

the below blows before I can specify the control I wish to manipulate

Function lblr(LO As Object, pntr As String)
'LO.Caption = DLookup("ListLbl", "ListLabel", "Code=" & pntr)
'DLookup("ListLbl", "ListLabel", "Code = pntr")
LO.Caption = DLookup("ListLbl", "ListLabel", "Code = pntr")
End Function
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim ctrl As Object
'Dim LblRef As String
Dim LblRef As Variant

L01.Caption = DLookup("ListLbl", "ListLabel", "Code='01'") '<<<This Works
For i = 2 To 10
Set ctrl = Nothing
LblRef = "L" & Format(i, "00")
Set ctrl.Type = Label
Set ctrl.Name = LblRef
ctrl.Caption = lblr(ctrl, Format(i, "00"))
Next i
....
 
G

Guest

Private Sub Form_Open(Cancel As Integer)
Dim LblRef As String
Dim rst As DAO.Recordset
Dim str

Set rst = CurrentDb.OpenRecordset("SELECT * FROM ListLabel WHERE Code
BETWEEM '01' AND '10';")

With rst
.MoveLast
.MoveFirst
Do While Not .EOF
strLblRef = "L" & !
Code:
Me.Controls(strLblRef).Caption = ![ListLbl]
.MoveNext
Loop
.Close
End With
 

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