Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

828 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