Solved

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

Posted on 2014-11-17
5
508 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

777 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