Solved

MS Access Loop Through All Forms and Write Label Captions to Table

Posted on 2014-11-17
5
483 Views
Last Modified: 2014-11-18
Hi,
A more challenging request than my last question:
I need to list the captions of the labels of all controls of all forms to tblMyTable.ObjectLabel
The respective Form name should be written to tblMyTable.ObjectName
(I'm unsure as to whether the control to which the label is associated/attached could also be listed to tblMyTable.ControlName since, I expect, I would first need to ensure that each Label is indeed associated with a control).
Your Assistance would be greatly appreciated.
Kind Regards,
Mohamed
0
Comment
Question by:Mohamed Singh
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Gozreh
ID: 40449006
once the form is open you can loop through all controls
      For Each ctl In Forms(frm.Name).Controls
         If ctl.ControlType = acLabel Then
            rs.AddNew
            rs!ObjectCaption = Forms(frm.Name).Caption
            rs!ObjectName = frm.Name
            rs!ObjectLabel = ctl.Name
            rs.Update
         End If
      Next ctl

Open in new window

0
 
LVL 10

Expert Comment

by:Gozreh
ID: 40449013
if you want to list the associated label you can add this code
            On Error Resume Next
            rs!ObjectLabel = ctl.Controls.Item(0).Caption
            On Error GoTo 0

Open in new window

0
 

Author Comment

by:Mohamed Singh
ID: 40449088
Hi Gozreh,
Thank You for responding.
The post ID : 40449013 does not return the label caption.
Kind Regards,
Mohamed
0
 
LVL 10

Accepted Solution

by:
Gozreh earned 500 total points
ID: 40449515
To get all text boxes control name you need to change the control type
If ctl.ControlType = acLabel Then

Open in new window

to acTextBoxes
Then it will give you the associated label connected to that textbox.

Or you can change it to
If ctl.ControlType <> acLabel Then

Open in new window

to exclude all label controls.
0
 

Author Comment

by:Mohamed Singh
ID: 40449784
Hi Gozreh,
Great stuff!
That works perfectly.
Kind Regards,
Mohamed
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now