Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Determine Button Section
Chris Bezant 
      
5 years ago
Hi Guys
I need to detect which section of a form a command button is in.
While looping through the collection of command buttons is there a way of determining which section of the form contains the button I.e . header, detail or footer?
Any help much appreciated.
Kevin Robertson  @Reply  
          
5 years ago
You could do something like this to determine the buttons in the Header Section of a form (for example)


    Dim ctrl As Control
    
    For Each ctrl In Me.Section(acHeader).Controls
        If ctrl.ControlType = acCommandButton Then
            MsgBox ctrl.Name
        End If
    Next

    
Chris Bezant OP  @Reply  
      
5 years ago
Thanks Kevin, but I am looping through all buttons on a form and need to know which section they are in.
To go your way I would need to loop through each section separately. I guess I could do that but I was hoping there was a better way.
Alex Hedley  @Reply  
           
5 years ago
Haven't checked but you might be able to loop through all the controls (Me.Controls) and there might be a section property you can check on.
Adam Schwanz  @Reply  
           
5 years ago
Yea just as Alex said, using basically same code Kevin gave you you can just do
Private Sub Command1_Click()
    Dim ctrl As Control
    
    For Each ctrl In Me
        MsgBox ctrl.Name & " " & ctrl.Section
    Next
End Sub


These are the values it returns
0 acDetail Form detail section
1 acHeader Form header section
2 acFooter Form footer section
3 acPageHeader Form page header section
4 acPageFooter Form page footer section
Richard Rost  @Reply  
          
5 years ago
Nice solution. :)
Chris Bezant OP  @Reply  
      
5 years ago
Thanks Adam
I'll give that a go tomorrow. Unfortunately it's bedtime right now :O(
Chris Bezant OP  @Reply  
      
5 years ago
Hi Guys
Thanks to you guys my code is working perfectly.
I have a colour system where the user can choose their own colours for form background and button colours.
It works by checking for keywords in the form caption and in the button captions.
The problem was that if I had, say, an entry for Email the email form background and a button containing the word email then were the same colour making the button hard to see.
By checking which form section contained the button I could ensure that the button did not get the same colour as the section background.
I am partially sighted so this colour feature makes my life much easier.
So, thanks again guys for taking the trouble to help.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access 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/8/2026 8:09:21 PM. PLT: 1s