Is it possible to see if more than one labels (on different forms/reports) are having same tag property? Can someone help me?
17 11428
Loop through all the controls (or just the labels if you prefer), checking for those with a specified tag value.
Then use Debug.Print ctrl.Name to display the names in the immediate window.
Or add each control name to a text string and when done, display in a message box or output to a text file.
NeoPa 32,556
Expert Mod 16PB
Hi there.
Are you asking about Controls with the same .Tag value across a single Form or Report? Or are you asking about such Controls which may be found across multiple Forms &/or Reports - as your question seems to imply?
Certainly it helps to understand that, unlike Controls themselves, which have Collection objects within various other objects - like Forms, Reports, Sections, etc - the .Tag property is quite a basic one that contains simple text. So, whether you're looking within a single Form/Report - or even just one of their Sections - or across multiple Control Collections - the technique would be to cycle through the elements of (all) the Collection(s) and compare the .Tag value of each to match what it is you're looking for.
In its simplest sense that would look something like : - For Each ctlVar In Me.Controls
-
On Error Resume Next
-
blnVar = False
-
blnVar = ctlVar.Tag >= ""
-
On Error GoTo 0 'or replace with whatever was used before.
-
If ctlVar.Tag = "Check value" Then
-
' ... Your code here for when a match is found.
-
End If
-
Next ctlVar
NB. Not all Controls even have a .Tag property so checking it for those would trigger an error that would need to be handled ;-)
NB. Checking for Control type would mean not needing to do the error handling bit as only certain Control types have a .Tag property.
Thank you @NeoPa for your response.
Or are you asking about such Controls which may be found across multiple Forms &/or Reports - as your question seems to imply?
Yes, the controls are to be compared across the forms and/or reports.
NB. Not all Controls even have a .Tag property so checking it for those would trigger an error that would need to be handled ;-)
NB. Checking for Control type would mean not needing to do the error handling bit as only certain Control types have a .Tag property.
I need comparing the .Tag property of only Lable controls for which we can use If ctl.controltype = acLabel Then .
NeoPa 32,556
Expert Mod 16PB mshakeelattari:
Yes, the controls are to be compared across the forms and/or reports.
So, what are you actually talking about? What are you doing that needs to process through multiple Forms & Reports? What do you have already that you can fit the extra code within? Remember - we aren't here simply to do your work for you. I understand English is not your first language, but you should understand that point by now (99 posts already - and for many of those I've had to repeat this point).
I can offer my earlier code modified to handle only Labels. That is pretty trivial : - For Each ctlVar In Me.Controls
-
If ctlVar.ControlType = acLabel Then
-
If ctlVar.Tag = "Check value" Then
-
' ... Your code here for when a match is found.
-
End If
-
End If
-
Next ctlVar
I created a Sub-Routine for you that will check every single Label in every Form, except the one passed to the Routine for a Tag Value that is also passed to the Routine. If a match, or matches are found, it prints the Form Name, Label Name, and Tag Value to the Immediate Window. This should be more than enough to point you in the right direction. -
Public Sub CheckTagValue(strCurrentForm As String, strTag As String)
-
Dim ctl As Control
-
Dim aobFrm As AccessObject
-
-
DoCmd.Hourglass True
-
-
For Each aobFrm In CurrentProject.AllForms
-
If aobFrm.Name <> strCurrentForm Then
-
DoCmd.OpenForm aobFrm.Name, acDesign, , , , acHidden
-
For Each ctl In Forms(aobFrm.Name)
-
If ctl.ControlType = acLabel And ctl.Tag = strTag Then
-
Debug.Print aobFrm.Name; Tab(25); ctl.Name; Tab(75); ctl.Tag
-
End If
-
Next
-
DoCmd.Close acForm, aobFrm.Name
-
End If
-
Next
-
-
DoCmd.Hourglass False
-
End Sub
-
-
Check all labels in all Forms, except Form3, for a Tag Value of 'Expenses2022'
-
Call CheckTagValue("Form3", "Expenses2022")
-
-
Form1 Label3 Expenses2022
-
Purchases Subform for Purchase Order Details
-
Unit Cost_Label Expenses2022
-
Order Subform for Order Details
-
Product ID_Label Expenses2022
-
Order Subform for Order Details
-
Status Name_Label Expenses2022
-
Customer Details Last Name_Label Expenses2022
-
Customer Details Notes_Label Expenses2022
-
Inventory List Current Level_Label Expenses2022
-
Shipper List Company_Label Expenses2022
-
Sales Analysis Form Product Name_Label Expenses2022
-
Sales Analysis Form Order Date_Label Expenses2022
-
Product Details Target Level_Label Expenses2022
-
Customers Label6 Expenses2022
-
Customers Label24 Expenses2022
-
Customers Label30 Expenses2022
-
Customers Label39 Expenses2022
-
NeoPa 32,556
Expert Mod 16PB
Hi ADezii old friend :-)
You may notice in the example code I gave earlier that I separated the check for Label & the value of .Tag into two If lines. This was no accident. Any Controls that have no .Tag property will crash in your example :-(
@NeoPa: Any Controls that have no .Tag property will crash in your example :-(
Excellent point, one that I obviously overlooked. One question to you my friend, I executed this Code against every single Form in the Northwind 2007 Sample Database, plus some that I created (40 Forms in all/900+ Controls) with no Errors. How is this so, what have I obviously overlooked?
@NeoPa
Sorry to tell you but both bound & unbound labels DO have a Tag property
It is true that labels don't have an Enabled or Locked property which may be what you were thinking of
@adezii
Does that answer your question?
@isladogs:
Thanks, but I think that NeoPa was referring to non-Label Controls, all of which will be tested for each Form within the loop. Let's see what he has to say.
Apologies - I misread the earlier comment and can see that @NeoPa was well aware the labels do have a Tag property.
If it is true that not all controls have a Tag value, then your code would indeed need to be adjusted for that.
However, I've previously checked all standard Access controls - all have a Tag property ...even a page break control.
I've only checked a few of the long list of ActiveX controls e.g. slider, animation, up/down, web browser, treeview ...
All of those also have a Tag property.
So I think you're probably safe with regard to the Tag property - though not if you were instead testing for e.g. Enabled
@isladogs: I executed this Code against every single Form in the Northwind 2007 Sample Database, plus some that I created (40 Forms in all/900+ Controls) with no Errors.
Taking the above into consideration, I would also say that I should be safe with the one-line Statement. See Attached Image as far as to what Controls the Tag Property Applies To:
Yes, I agree.
Also bear in mind that MS loves to put all its latest 'features' in their template databases, so I expect you've already tested most if not all the standard controls and possibly some of the ActiveX ones .....
I'd be interested to see the article you got that from.
Can you pass on the URL.
BTW it seems to omit some standard controls I tested e.g. WebBrowser
Thanks a lot.
Oops too short - minimum 20 characters
NeoPa 32,556
Expert Mod 16PB NeoPa 32,556
Expert Mod 16PB
In truth, I can't list which Controls have the .Tag Property & which don't. I can tell you though, that the Control object itself - on which all Controls are built - does not have a .Tag property. Use F2 to confirm this for yourself by examining the Access.Control object.
Thus is makes good sense for disciplined coding to ensure that is checked for before using it. I have two sets of code below that show two different approaches to the checking. We know all Labels have it; we also know that if we handle its absence then any following code is safe.
<<Too short huh? >>
I always forget that work round!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Circe |
last post by:
In vb excel i can load a form and write this code for adding labels that
i need during program execution
Set l = frmOrders.Controls.Add("Forms.Label.1")
With l
.Caption = "January"
.FontBold...
|
by: keithb |
last post by:
I posted this question earlier with an unclear predicate. Let me give it
another shot:
I have found that unless I re-create dynamically added controls on every
postback, I am unable to access...
|
by: bearmstrong |
last post by:
Here's what i need to do, keep in mind that I'm new to access and have learned coding is the same as excel.
I have 2 different types of users, those that are users and those that are admin. I have...
|
by: Max |
last post by:
I am editting a database created in access 2003 by another programmer.
This person has left the company for which the database was created and
no documentation. So that I could work on this...
|
by: jdurell |
last post by:
I am trying to work with a copy of an access database but I cannot seem
to access the forms/reports or code. I am holding shift to go in the
back door The queries and tables are there but thats...
|
by: erri |
last post by:
Is there a way to split the contents of one table into different forms (i.e. subform1 = LastName A-F, subform2 = LastName F-M, etc) without having to make queries?
|
by: Zabooster |
last post by:
Hi all,
I have to submit a project in 2 days' time and am currently challenged trying to send information inputted into textboxes, radiobuttons and checkboxes present in different forms to a sigle...
|
by: titli |
last post by:
Hi All,
Please tell me the best solution to implemenet security in access databases , to save the tables, queries, forms , reports as well as the VBA code from user access.
The users of the...
|
by: slenish |
last post by:
Hello,
I am having a problem with a query attatched to a report. I have two different forms that I want to be able to run the same report with.
Example: Form(A) is open I input a date range in...
|
by: Hamdii |
last post by:
Dear All,
I'm really blocked and tired from looking for code or option makes me able to perform the autoscaling of my controls and forms in vb.net.
does any one here who could help me please...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |