Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

757 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

19 Experts available now in Live!

Get 1:1 Help Now