How to store my buttons in an array

Posted on 2003-02-27
Medium Priority
Last Modified: 2010-05-01
Hi all

I want to store my commandButtons in an array

Dim arrCmdButtons(11) As CommandButton

'-- initialize this array with command buttons

arrCmdButtons(0) = R_cmdAddGS
arrCmdButtons(1) = R_cmdRemoveGS
arrCmdButtons(2) = R_cmdUp
arrCmdButtons(3) = R_cmdDown
arrCmdButtons(4) = R_cmdBoarding
arrCmdButtons(5) = R_cmdGrooming
arrCmdButtons(6) = R_cmdEdit
arrCmdButtons(7) = R_cmdReserve
arrCmdButtons(8) = R_cmdTransac
arrCmdButtons(9) = R_cmdCancel
arrCmdButtons(10) = R_cmdBook

but I am getting the following: object or variable is not set.

What you think the problem is ?
Question by:Ramesh4u
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 70

Accepted Solution

Éric Moreau earned 60 total points
ID: 8039087
because CommandButton are objects, you need to use SET:

SET arrCmdButtons(0) = R_cmdAddGS

Expert Comment

ID: 8039244
hi ram,

The easy way to create a control array is in design mode
put the command button on the form.Name it
arrCmdButtons then set index = 0.

now you can add more buttons with Load as follows:

Private Sub Form_DblClick()
For i = 1 To 10
Load arrCmdButtons(i)
arrCmdButtons(i).Left = arrCmdButtons(i - 1).Left
arrCmdButtons(i).Top = arrCmdButtons(i - 1).Top + arrCmdButtons(i_1).Height
arrCmdButtons(i).Visible = True
arrCmdButtons(1).Caption = "R_cmdRemoveGS"
' etc to put Captions on the buttons
End Sub

In design mode I set arrCmdButtons(0) = R_cmdAddGS

I just used Form_DblClick()to launch the Load thing.
You could launch it however you wish


Author Comment

ID: 8041388

Thank you emoreau

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question