473,882 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search QueryDefs, Reports and Form controls for a string

2,322 Recognized Expert Moderator Top Contributor
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.

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
  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
  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
  16.          End Select
  17.       Next
  18.       DoCmd.Close acForm, oAO.Name, acSaveNo
  19.    Next
  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
  11.             Case acTextBox, acComboBox, acCheckBox
  12.                If InStr(1, ctrl.ControlSource & "", strSearchWord) Then
  13.                   Debug.Print "Report:" & rpt.Name & ": " & ctrl.Name
  14.                End If
  16.          End Select
  17.       Next
  18.       DoCmd.Close acReport, oAO.Name, acSaveNo
  19.    Next
  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

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
10 13308
3,653 Recognized Expert Moderator Specialist
Also, just thinking about this, Smiley.... You mentioned in the original post that it is easy enough to search modules for a string. however, if one has several modules, and many forms and reports with modules, it would entail searching each module individually. I tried playing with the code for the modules, but admittedly, I have no idea where to start....
Oct 16 '12 #11

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

Similar topics

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?
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...
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:
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...
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...
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
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?
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:
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/ >
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 -...
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...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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,...
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...
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...
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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.