Solved

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

Posted on 2014-11-17
5
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

696 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