We live on a hunk of rock and metal that circles a humdrum star that is one of 400 billion other stars that make up the Milky Way Galaxy which is one of billions of other galaxies which make up a universe...
I try to handle some 500 buttons in my access db project.
And as we know, button name can not be Button(1) as an array.
But I found an interesting work-around.
Dim cmdButtons(1 to 5) as Control Dim I as Integer
Set cmdButtons(1) = me.cmdButton1 Set cmdButtons(2) = me.cmdButton2 Set cmdButtons(3) = me.cmdButton3 Set cmdButtons(4) = me.cmdButton4 Set cmdButtons(5) = me.cmdButton5
For I = 1 to 5 CmdButtons(I).caption = "Button " & I Next I
Is this a reliable work-around, manipulating the button name as an array, or a fake way with problems later ?
Benifits: I can still use the real name when making simple vb code, and use the array-name in for-next and more complicated vb repitisions.
Is there any down sides or other benifits with this metode handling 500 buttons ?
ystein
Kevin Robertson
@Reply 9 months ago
Are you manually going to set the Array Index for 500 buttons?
Do all your Buttons have a numeric suffix?
Try doing it like this.
Dim buttonArray(1 To 5) As Control
Dim X As Long
For X = LBound(buttonArray) To UBound(buttonArray)
On Error Resume Next
Me.Controls("btn" & X).Caption = "Buffy " & X
On Error GoTo 0
Next
I named my buttons (btn1, btn2, btn3, btn4, btn5)
I added some error handling in case there is a missing number.
Note: This will only work for buttons on the current form.
Raymond Spornhauer
@Reply 9 months ago
@0[ystein-Frostad]
What are you really trying to accomplish? Why do you need 500 buttons?
It would be easier to help with a solution if we know what you're trying to accomplish.
Examples:
- Instead of 500 buttons... you could have a combo box with 500 entries with 1 button.
- You could have a Button Table for all of your buttons, then use the Tag property to set them all with a recordset.
- You could a group of buttons to change another group of buttons
- Etc.
Give a better description of what you really want to accomplish with some pictures so we can better help.
-Raymond
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.