Computer Learning Zone CLZ Access Excel Word Windows

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...

-Carl Sagan
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Buttons array again
ystein Frostad 

9 months ago
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

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 11:26:03 AM. PLT: 0s