Is it possible to see if more than one labels (on different forms/reports) are having same tag property? Can someone help me?
17 11421
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,554
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,554
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,554
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,554
Expert Mod 16PB NeoPa 32,554
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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |