473,883 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search QueryDefs, Reports and Form controls for a string

TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Introduction
This article will explain how you can search your current application for a specified string.

Not often, but once in a while I need to change a field name, in order to for it to make more sense, often because I need to add an extra field, and with the new field, there might be ambiguity as to the meaning of each field.

Therefore I made a simple bit of code that will check (not auto-correct) your QueryDefs, the control source of controls in your your forms and reports.

Note that stored queries (such as a forms Recordsource, or a combobox Rowsource) are stored in the QueryDefs collection, and as such are included in this search.



Implementation:
I have created it as three separate functions, one for queries,one for forms, and one for reports, as well as a function combining the use of all three. The functions are shown below:

For Queries
Expand|Select|Wrap|Line Numbers
  1. Public Sub SearchQueryDefs(strSearchWord As String)
  2.    Dim qdf As DAO.QueryDef
  3.    Dim strSQL As String
  4.    For Each qdf In CurrentDb.QueryDefs
  5.       strSQL = qdf.SQL
  6.       If InStr(1, strSQL, strSearchWord, vbTextCompare) > 0 Then
  7.          Debug.Print "Query: " & qdf.Name
  8.       End If
  9.  
  10.    Next
  11.    Set qdf = Nothing
  12. End Sub
Example output looks like:
Expand|Select|Wrap|Line Numbers
  1. Query: ~sq_ffrm_List_My_Reviews
  2. Query: ~sq_ffrm_ListReviewsByDate
  3. Query: qry_ExportReviewOverviewToExcel
  4. Query: qry_ReviewDoc
You may notice the ~sq which means this is a stored query, in this first case its the underlying recordsource for my frm_List_My_Rev iews.

On occasion while using this you might find that a query which has been deleted is returned. This is due to the way access stores/caches the queries. You can usually remove these by a Compact And Repair operation. If not this could be a sign of database corruption.

For Forms
For forms, I open each form in design view, and loop over the controls collection. I only check Textbox, combobox, listbox and checkbox, but if needed it could be expanded to check such items as bound pictures. Finally the form is closed again, ensuring that no changes are saved. BEFORE RUNNING you should close all forms.
Expand|Select|Wrap|Line Numbers
  1. Public Sub searchForms(strSearchWord As String)
  2.    Dim oAO As Object
  3.    Dim frm As Form
  4.    Dim ctrl As Object
  5.    For Each oAO In CurrentProject.AllForms
  6.       DoCmd.OpenForm oAO.Name, acDesign
  7.       Set frm = Forms(oAO.Name)
  8.       For Each ctrl In frm.Controls
  9.          Select Case ctrl.ControlType
  10.  
  11.             Case acTextBox, acComboBox, acListBox, acCheckBox
  12.                If InStr(1, ctrl.ControlSource & "", strSearchWord) Then
  13.                   Debug.Print "Form: " & frm.Name & ": " & ctrl.Name
  14.                End If
  15.  
  16.          End Select
  17.       Next
  18.       DoCmd.Close acForm, oAO.Name, acSaveNo
  19.    Next
  20.  
  21.  
  22.    Set oAO = Nothing
  23.    Set frm= Nothing
  24.    Set ctrl = Nothing
  25. End Sub
Example output looks like:
Expand|Select|Wrap|Line Numbers
  1. Form: frm_ReviewDetails: tb_DateSubmitted
  2. Form: frm_Obs: tb_DateSubmitted
For Reports
This implementation is quite similar to the how the forms are searched exept I loop over the AllReports collection.
Expand|Select|Wrap|Line Numbers
  1. Public Sub searchReports(strSearchWord As String)
  2.    Dim oAO As Object
  3.    Dim rpt As Report
  4.    Dim ctrl As Object
  5.    For Each oAO In CurrentProject.AllReports
  6.       DoCmd.OpenReport oAO.Name, acDesign
  7.       Set rpt = Reports(oAO.Name)
  8.       For Each ctrl In rpt.Controls
  9.          Select Case ctrl.ControlType
  10.  
  11.             Case acTextBox, acComboBox, acCheckBox
  12.                If InStr(1, ctrl.ControlSource & "", strSearchWord) Then
  13.                   Debug.Print "Report:" & rpt.Name & ": " & ctrl.Name
  14.                End If
  15.  
  16.          End Select
  17.       Next
  18.       DoCmd.Close acReport, oAO.Name, acSaveNo
  19.    Next
  20.  
  21.  
  22.    Set oAO = Nothing
  23.    Set rpt = Nothing
  24.    Set ctrl = Nothing
Example Output:
Expand|Select|Wrap|Line Numbers
  1. Report:rep_Main: tb_DateSubmitted
  2. Report:supRep_Obs: tb_DateSubmitted

Modules
While it is possible to loop over the modules and check them in a similar way, its easy enough to use standard Find built into the VB-Environment so I have not made code for this.

Combine the 3 into a single call
For ease of use, I choose to combine the 3 functions into a single call:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SearchDBObjects(strSearchWord As String)
  2.     SearchQueryDefs strSearchWord
  3.     searchForms strSearchWord
  4.     searchReports strSearchWord
  5. End Sub

I hope this can be usefull to someone. If you found this article usefull please post here, link to it, share it. You are welcome to use any and all parts of the code shown.
Aug 28 '12 #1
10 13309
twinnyfo
3,653 Recognized Expert Moderator Specialist
Wow, Smiley! You read my mind. I was just thinking about posting this as a question, as I have had to do manual searches in the past. What a time saver! Thanks for your article!
Aug 28 '12 #2
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Thanks for the feedback. Its nice to know that the time spent on writing the article was not wasted. :)
Aug 28 '12 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
And........... Thanks to this handy dandy little code, I just had to use it this morning. Rather than searching 400 queries by hand, I could now identify the 60 queries affected ....

Endless time save, Smiley! Thanks again!
Aug 29 '12 #4
twinnyfo
3,653 Recognized Expert Moderator Specialist
Smiley,

Your code above works for the QueryDefs, but when I look in the Reports and Forms, I get an error when I get to this line:

Expand|Select|Wrap|Line Numbers
  1. For Each oAO In CurrentProject.AllForms
  2. For Each oAO In CurrentProject.AllReports
  3.  
When I checked it at home, it worked fine. Office has 2007, Home has 2010.

Any ideas why these would behave differently?
Aug 30 '12 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I am guessing that AccessObject has only been added in version 2010. Replace the lines
Expand|Select|Wrap|Line Numbers
  1. Dim oAO As AccessObject
with
Expand|Select|Wrap|Line Numbers
  1. Dim oAO As Object
and the code should run fine in Access 2007.

I will update the original post to be compatible with Access 2007. I do believe that this new version is Ac2000+ compatible.
Aug 30 '12 #6
twinnyfo
3,653 Recognized Expert Moderator Specialist
Many thanks as usual, Smiley!
Aug 30 '12 #7
twinnyfo
3,653 Recognized Expert Moderator Specialist
Still getting the same error on the same lines:

Invalid qualifier
Aug 30 '12 #8
twinnyfo
3,653 Recognized Expert Moderator Specialist
Here is what I have found to get rid of any errors:

Expand|Select|Wrap|Line Numbers
  1. Public Sub SearchForms(strSearchWord As String)
  2.     Dim dbs As Object
  3.     Dim oAO As AccessObject
  4.     Dim frm As Form
  5.     Dim ctrl As Object
  6.     Set dbs = Application.CurrentProject
  7.     For Each oAO In dbs.AllForms
  8.         DoCmd.OpenForm oAO.Name, acDesign
  9.         Set frm = Forms(oAO.Name)
  10.         For Each ctrl In frm.Controls
  11.             Select Case ctrl.ControlType
  12.                 Case acTextBox, acComboBox, acListBox, acCheckBox
  13.                     If InStr(1, ctrl.ControlSource & "", strSearchWord) Then
  14.                         Debug.Print "Form: " & frm.Name & ": " & ctrl.Name
  15.                     End If
  16.             End Select
  17.         Next
  18.         DoCmd.Close acForm, oAO.Name, acSaveNo
  19.     Next
  20.     Set oAO = Nothing
  21.     Set frm = Nothing
  22.     Set ctrl = Nothing
  23. End Sub
  24.  
The report version of this code works and works on most of my forms, but one one particular form, I get a strange error:

You entered an expression that has an invlaid reference to the property ControlSource.

Any ideas? I'm trying to figure out which control and where this error is occuring.
Aug 30 '12 #9
twinnyfo
3,653 Recognized Expert Moderator Specialist
It appears that checkboxes within option groups do not have a control source. The option group itself has a control source, but the individual checkboxes do not. How do we check to see if a control has a particular property available?
Aug 30 '12 #10

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

Similar topics

3
3095
by: Davey | last post by:
Is it possible to add new form controls such as <select> and <input> controls using JavaScript - all client-side and on-the fly?
0
3102
by: Lauren Quantrell | last post by:
In terms of resources, wondering if it makes a difference in adopting one of the three options below for resizing controls on a form and controls on a subform at the same time. option a.) Put the code all in the main form and refer to the controls on the subform in the main form's OnResize event. option b.) Put the code for the main form controls in the main form's OnResize event and put the code for the subform controls in the...
4
2341
by: Dries De Rudder | last post by:
Hi, I am trying to bind an object to form controls. I've got an object MyObject which has some properties e.g. ID. I've got a form, Form1, that contains a textbox ,TextBox1, now I want to bind the value of the ID-property of a MyObject-object to the TextBox1. I've tried doing this:
2
1685
by: Adam Right | last post by:
Hi, I want to get the controls of the windows form. I know that form.Controls give me the list of controls but i have a problem. For example, the toolstripmenu control cannot be reached with that way. My goal is to list the items of the toolstripmenuitem on the form. I have only the typename of the windows form so i am invoking the form with its typename, and i can reach the controls like buttons,labels etc. But i cannot get the...
8
3601
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
4
1850
by: DFS | last post by:
'Search all reports for a text box named something Dim cMsg As String, db As Database, rs As Recordset, rpt As Report, ctl as Control Set db = CurrentDb() cMsg = "BuildingID" Set rs = db.OpenRecordset("SELECT AS REPORTOBJ FROM MSYSOBJECTS WHERE = -32764;") Do Until rs.EOF
16
4185
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and therefore being able to modify its properties?
11
4244
by: dhtml | last post by:
(originally mis-posted on m.p.s.jscript...) I've just closed all windows in Firefox and its using 244MB of memory. I have no idea why. I had GMail open, a page from unicode, the CLJ FAQ. I've noticed that createElement leaks. It's obvious with form controls because the form keeps the control name as a property. Example:
9
2526
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett -- comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
10
44105
by: =?Utf-8?B?UmljaA==?= | last post by:
A lot of users at my workplace use different screen resolutions, and I build apps to use 1680 x 1050 pixels res by default. But some users are using 800 x 600, and the apps are too large for their screen. I used to write code in Java a few years ago (2005), and you could stretch a form with the mouse and all the controls and fonts would resize to larger or smaller size. Does .Net framework 3.5 support this kind of functionality? Or -...
0
9932
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11109
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10728
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10405
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9558
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7959
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5782
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.