Populate button caption from table

Robbie1974

New member
Local time
Today, 04:09
Joined
Mar 31, 2005
Messages
8
I'm trying to populate the captions from the buttons on my form with names from my table.

I have a table captions with the field names.
I have a form with 30 buttons not visible. All have the same caption button0.

This is the code I have so far:

Code:
Dim DB As DAO.Database, rst As DAO.Recordset, ctl As Control
   
   Set DB = CurrentDb
   Set rst = DB.OpenRecordset("captions", dbOpenDynaset)
   
   For Each ctl In Me.Controls
      ctl.Caption = name
      ctl.Visible = True
   Next
   
   Set rst = Nothing
   Set DB = Nothing

This updates all buttons with the same name.

How do I get it to update to the following:

For every record in the table make the button visible and update it's caption.

Do I have to work with do while? And how do I do that?


Any help, because I'm stuck?
 
How do you know what record in "captions" goes with what button on your form?
 
This works for me, after reading the control name from a table, I set the variable ctltxt to the value from the table. Then I read the next record and repeat the process.

With Me.Controls(ctltxt)
.Top = topini
.Left = 2020
.TabStop = True
.TabIndex = rs!TbOrder
.Width = rs!CtrlWidth
.Visible = True
End With

Your code seems to be missing the control name and the record loop, so you open a recordset and , you loop through all the contols and set them the same and you end up with them all set to the caption of the first record.

You need
do while not rs.eof
rs.movefirst
ctltxt = rs!ControlName
ctlcp = rs!ControlCaption
...
rs.movenext
loop

then do something like what I've done above using the control name and control caption.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom