473,288 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

How to find the controls on different forms or reports having same tag?

99 64KB
Is it possible to see if more than one labels (on different forms/reports) are having same tag property? Can someone help me?
Aug 7 '22 #1
17 11421
isladogs
454 Expert Mod 256MB
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.
Aug 7 '22 #2
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 :
Expand|Select|Wrap|Line Numbers
  1. For Each ctlVar In Me.Controls
  2.     On Error Resume Next
  3.     blnVar = False
  4.     blnVar = ctlVar.Tag >= ""
  5.     On Error GoTo 0     'or replace with whatever was used before.
  6.     If ctlVar.Tag = "Check value" Then
  7.         ' ... Your code here for when a match is found.
  8.     End If
  9. 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.
Aug 7 '22 #3
mshakeelattari
99 64KB
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 .
Aug 8 '22 #4
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 :
Expand|Select|Wrap|Line Numbers
  1. For Each ctlVar In Me.Controls
  2.     If ctlVar.ControlType = acLabel Then
  3.         If ctlVar.Tag = "Check value" Then
  4.             ' ... Your code here for when a match is found.
  5.         End If
  6.     End If
  7. Next ctlVar
Aug 8 '22 #5
ADezii
8,834 Expert 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. Public Sub CheckTagValue(strCurrentForm As String, strTag As String)
  2. Dim ctl As Control
  3. Dim aobFrm As AccessObject
  4.  
  5. DoCmd.Hourglass True
  6.  
  7. For Each aobFrm In CurrentProject.AllForms
  8.   If aobFrm.Name <> strCurrentForm Then
  9.     DoCmd.OpenForm aobFrm.Name, acDesign, , , , acHidden
  10.       For Each ctl In Forms(aobFrm.Name)
  11.         If ctl.ControlType = acLabel And ctl.Tag = strTag Then
  12.           Debug.Print aobFrm.Name; Tab(25); ctl.Name; Tab(75); ctl.Tag
  13.         End If
  14.       Next
  15.     DoCmd.Close acForm, aobFrm.Name
  16.   End If
  17. Next
  18.  
  19. DoCmd.Hourglass False
  20. End Sub
  21.  
Expand|Select|Wrap|Line Numbers
  1. Check all labels in all Forms, except Form3, for a Tag Value of 'Expenses2022'
  2. Call CheckTagValue("Form3", "Expenses2022")
  3.  
Expand|Select|Wrap|Line Numbers
  1. Form1                   Label3                                            Expenses2022
  2. Purchases Subform for Purchase Order Details
  3.                         Unit Cost_Label                                   Expenses2022
  4. Order Subform for Order Details
  5.                         Product ID_Label                                  Expenses2022
  6. Order Subform for Order Details
  7.                         Status Name_Label                                 Expenses2022
  8. Customer Details        Last Name_Label                                   Expenses2022
  9. Customer Details        Notes_Label                                       Expenses2022
  10. Inventory List          Current Level_Label                               Expenses2022
  11. Shipper List            Company_Label                                     Expenses2022
  12. Sales Analysis Form     Product Name_Label                                Expenses2022
  13. Sales Analysis Form     Order Date_Label                                  Expenses2022
  14. Product Details         Target Level_Label                                Expenses2022
  15. Customers               Label6                                            Expenses2022
  16. Customers               Label24                                           Expenses2022
  17. Customers               Label30                                           Expenses2022
  18. Customers               Label39                                           Expenses2022
  19.  
Aug 13 '22 #6
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 :-(
Aug 13 '22 #7
ADezii
8,834 Expert 8TB
@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?
Aug 13 '22 #8
isladogs
454 Expert Mod 256MB
@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?
Aug 14 '22 #9
ADezii
8,834 Expert 8TB
@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.
Aug 14 '22 #10
isladogs
454 Expert Mod 256MB
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
Aug 14 '22 #11
ADezii
8,834 Expert 8TB
@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:
Attached Images
File Type: jpg Capture2.JPG (60.4 KB, 43 views)
Aug 14 '22 #12
isladogs
454 Expert Mod 256MB
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
Aug 14 '22 #13
isladogs
454 Expert Mod 256MB
Thanks a lot.
Oops too short - minimum 20 characters
Aug 14 '22 #15
NeoPa
32,554 Expert Mod 16PB
Too short huh?
Aug 14 '22 #16
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.
Aug 14 '22 #17
isladogs
454 Expert Mod 256MB
<<Too short huh? >>
I always forget that work round!
Aug 15 '22 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
0
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...
1
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...
2
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...
1
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...
1
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?
3
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...
1
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...
20
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...
1
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...
2
isladogs
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...
0
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"....
0
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...
0
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 =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.