how to create an array of commandbutton in aform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i would like to create an array of commandbutton ( for example 20
commandbutons) in a form with VBA . How i do it
 
gevolosgre said:
i would like to create an array of commandbutton ( for example 20
commandbutons) in a form with VBA . How i do it


Access does not have control arrays.

Create a command button and set all its properties as
desired. Then use Copy and Paste it 19 times. Drag a
selection box around a set of them and set their Top or Left
property. Then select each one in turn and set it's name
property to somsthing like cmd1, cmd2, etc. You can then
refer to the Nth button using the syntax:
Me("cmd" & N)
 
I just did this over the weekend. I am using an existing form and
opening it in design mode and then adding the controls based on data in
a table. You can also use CreateForm to start with a new form.

DoCmd.OpenForm "frmPanelRightTemplate", acDesign, , , , acHidden
Set db = CurrentDb
Set rs = db.OpenRecordset("qryRightPanelFastener")
'For each Right Panel fastener add a command button and set
properties

rs.MoveFirst
DoCmd.SetWarnings (off)
Do While Not rs.EOF

Set ctl = CreateControl("frmPanelRightTemplate",
acCommandButton, , , , rs![FastenerXCoordinate] * 1440,
rs![FastenerYCoordinate] * 1440)
ctl.Caption = rs![FastenerNumber]
ctl.Height = 0.275 * 1440
ctl.Width = 0.275 * 1440
ctl.FontSize = 7
ctl.TabStop = False
ctl.Name = "cmd" & rs![FastenerNumber]
'ctl.FontWeight = "bold"

rs.MoveNext
Loop

DoCmd.Save
 

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

Back
Top