Controlling controls

G

Guest

Hi All,

I have a module that sets up my form. What I mean by "sets up" is that the
controls (check boxes w/ labels) need to be dynamic. The reason for this is
that the segmentation within my company changes occassionally and I need to
have my forms pick up these changes on the fly. Unfortunately, I can't
create controls on the fly and also assign them On_Click code. So my
solution is this: set up my form with all possible controls (check boxes w/
labels) with generic names, code their events as required and then in the On
Open event of the form pick up the data from the ODBC tables indicating which
segments to show. Confused yet? In a nutshell this is what the code does:
it first makes all the applicable controls invisible; then it assigns the
appropriate controls a caption and then - and here's what DOESN'T work - I
want to make only these controls visible again. The lines that don't seem to
work are:

frm(lbl).Visible = True

Any help? Clarification? I'm puzzled as to why this doesn't work. If I
comment out the invisible part all my labels are coming up correctly.



Function Set_Labels(sql$, frm As Form)
Dim dbs As Database, rst As Recordset, lbl$, i%, lob_1$, lob_2$, LOB_lbl$
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(sql)
For i = 0 To frm.Controls.count - 1
If frm.Controls.Item(i).ControlType = acLabel Or
frm.Controls.Item(i).ControlType = acCheckBox Then
If InStr(1, frm.Controls.Item(i).Name, "_") <> 0 Then
frm.Controls.Item(i).Visible = False
i = i + 1
End If
End If
Next i
i = 1
lob_1 = rst.Fields("ALM_LOB_ID").Value
rst.MoveNext
lob_2 = rst.Fields("ALM_LOB_ID").Value
rst.MoveFirst
Do Until rst.EOF = True
lbl = rst.Fields("Alm_Account").Value & "_" &
Trim(rst.Fields("ALM_LOB_ID").Value) & "_" _
& i & "_lbl"
frm(lbl).Caption = Trim(rst.Fields("Segment_ID").Value)
If InStr(1, frm(lbl).Caption, "&") <> 0 Then
frm(lbl).Caption = Left(frm(lbl).Caption, InStr(1,
frm(lbl).Caption, "&") - 1) _
& "&&" & Right(frm(lbl).Caption, Len(frm(lbl).Caption) -
InStr(1, frm(lbl).Caption, "&"))
End If
frm(lbl).Visible = True
LOB_lbl = rst.Fields("Alm_Account").Value & "_" &
Trim(rst.Fields("ALM_LOB_ID").Value)
frm(lbl).Visible = True
LOB_lbl = LOB_lbl & "_lbl"
frm(lbl).Visible = True
lob_2 = rst.Fields("ALM_LOB_ID").Value
rst.MoveNext
If rst.EOF = False Then
lob_1 = rst.Fields("ALM_LOB_ID").Value
If lob_1 = lob_2 Then
i = i + 1
Else
i = 1
End If
End If
Loop
rst.Close
Set dbs = Nothing
End Function
 
A

Allen Browne

Are these labels attached to a check box that is not visible?

If a label is attached to a hidden control, Access will not display it,
regardless of how the label's Visible property is set.
 
G

Guest

Thanks for the insight - I did stumble across that fact (one that I knew, but
had obviously momentarily forgotten) and things are working ok now. Thanks
again!
 

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