473,403 Members | 2,354 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,403 software developers and data experts.

Search for string in query?

prn
254 Expert 100+
Hi folks,

I have an inherited access application. At least a half-dozen people have worked on this one before me. The application contains hundreds of queries.

My (current) problem involves some information that is encoded in, shall we say, a non-intuitive way. And that encoding has changed over the years. One of my users noticed today that a report she ran produced an unexpected result. Tracking it down, I found that different queries treated this particular encoding differently, so I checked further and determined which treatment was correct, but now the question is are there other queries that use the old, bad criteria?

As I said, there are hundreds of queries here. Some of them are unused. Some were ad-hoc queries. But there are still hundreds. If I just had to search the VB code, that would be no problem. However, I don't know of a comparable method for searching the contents of queries. There is a characteristic string I could search for, but how to search?

Any thoughts?

Thanks,
Paul
Dec 18 '08 #1
13 9031
MMcCarthy
14,534 Expert Mod 8TB
Hi Paul

My advice is to use the built in Documenter Go to Tools Menu - Analyse - Documenter.

Go to the queries tab and select all. Then go to options and tick the sql box. Make sure the other options are not ticked or set to nothing. When run this produces an access report of all the SQL code for each query. You cannot save this document but you can print it or export it as a rtf for example.

You can then search the text.

Mary
Dec 18 '08 #2
prn
254 Expert 100+
Hi Mary,

Thanks for the tip. I had forgotten about the documenter. It's going to be a major operation to extract almost a thousand queries at once, but I guess this may be the only way to search them all. I think I'll let it run overnight. :)

Thanks,
Paul
Dec 18 '08 #3
MMcCarthy
14,534 Expert Mod 8TB
@prn
There is a vba code solution but I think it would be very heavy. Essentially it would be a matter of opening every query in query definition and searching the sql for key words, then closing that query and looping to the next one. I can't imagine it would be anything but onerous considering the number of queries. Actually I'm even trying to think how to search the sql as it's not something I would normally do.
Dec 18 '08 #4
prn
254 Expert 100+
@msquared
I get the feeling that it's not something that most people normally do. I tend to be an exception to that, I guess. I like to be able to search for things so that I know what needs to be fixed. On occasions like this I feel uncomfortable about Access, but I do appreciate the power of Access as a tool most of the rest of the time.

Thanks again,
Paul
Dec 18 '08 #5
MMcCarthy
14,534 Expert Mod 8TB
@prn
If you run into problems come back and we'll try to come up with a VBA solution.

And you are right, Access is a great tool but you have to be patient with it's idiosyncrasies as a developer.
Dec 18 '08 #6
prn
254 Expert 100+
Well, the Documenter is running at this very moment. When I come to work tomorrow morning, I'll find out how well it did or did not do. Access is a terrific tool, but, like all tools, it can be frustrating when you need to do something that your tool was not designed for.

Thanks,
Paul
Dec 18 '08 #7
prn
254 Expert 100+
WOW! That actually worked already! I was able to export it (File > Export) to a .txt file and now I can search that for the diagnostic strings.

That was great!

Thanks so much, Mary!

Paul
Dec 18 '08 #8
MMcCarthy
14,534 Expert Mod 8TB
You're welcome :D
Dec 18 '08 #9
NeoPa
32,556 Expert Mod 16PB
The Documenter shouldn't take too long to work at all Paul. You won't need to leave it running overnight. I usually save it (export it) as rtf then open it in MS Word. That way you have the power of Word searching to find your patterns etc.

PS. The choosing of the settings should probably take you longer than it will take Access to produce the report ;)
Dec 22 '08 #10
NeoPa
32,556 Expert Mod 16PB
Alternatively try this code in a procedure somewhere. I tested it in a form's open procedure.
Expand|Select|Wrap|Line Numbers
  1.     Dim qry As QueryDef
  2.  
  3.     For Each qry In CurrentDb.QueryDefs
  4.         If InStr(1, qry.SQL, "Your Search String") > 0 Then Debug.Print qry.Name
  5.     Next qry
PS. Don't forget to use Ctrl-G to show the results in the Immediate Pane ;)
Dec 22 '08 #11
ADezii
8,834 Expert 8TB
@prn
Hello prn! I basically expanded NeoPa's idea. Why not pinpoint exactly the Queries in which your Keywords appear?
  1. Create a Table named tblKeywords with a single Field named Keyword {TEXT}
  2. Populate this Field with all the Keywords on which you want to search for.
  3. Run this generic code.
    Expand|Select|Wrap|Line Numbers
    1. Dim qdf As DAO.QueryDef
    2. Dim MyDB As DAO.Database
    3. Dim rstKeywords As DAO.Recordset
    4.  
    5. Set MyDB = CurrentDb
    6.  
    7. Set rstKeywords = MyDB.OpenRecordset("tblKeywords", dbOpenForwardOnly)
    8.  
    9. With rstKeywords
    10.   Do While Not .EOF
    11.     For Each qdf In CurrentDb.QueryDefs
    12.       If Left$(qdf.Name, 3) <> "~sq" Then         'Filter out Tem Queries
    13.         If InStr(qdf.SQL, ![Keyword]) > 0 Then      'Keyword found in SQL
    14.           Debug.Print "Keyword [" & ![Keyword] & "] found in SQL for {" & qdf.Name & "}"
    15.         End If
    16.       End If
    17.     Next
    18.     .MoveNext
    19.   Loop
    20. End With
    21.  
    22. rstKeywords.Close
    23. Set rstKeywords = Nothing
SAMPLE OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Keyword [Employees] found in SQL for {Employee Sales by Country}
  2. Keyword [Employees] found in SQL for {Invoices}
  3. Keyword [Employees] found in SQL for {qry_OptimizeIt3}
  4. Keyword [Employees] found in SQL for {qryEmployees}
  5. Keyword [Employees] found in SQL for {qryEmployees_2}
  6. Keyword [Employees] found in SQL for {qryReport}
  7. Keyword [Employees] found in SQL for {Query1}
  8. Keyword [Employees] found in SQL for {Query3}
  9. Keyword [Employees] found in SQL for {Query5}
  10. Keyword [Employees] found in SQL for {Query6}
  11. Keyword [UnitPrice] found in SQL for {Invoices}
  12. Keyword [UnitPrice] found in SQL for {Order Details Extended}
  13. Keyword [UnitPrice] found in SQL for {Order Subtotals}
  14. Keyword [UnitPrice] found in SQL for {Product Sales for 1997}
  15. Keyword [UnitPrice] found in SQL for {Products Above Average Price}
  16. Keyword [UnitPrice] found in SQL for {Quarterly Orders by Product}
  17. Keyword [UnitPrice] found in SQL for {Ten Most Expensive Products}
  18. Keyword [OrderID] found in SQL for {Employee Sales by Country}
  19. Keyword [OrderID] found in SQL for {Invoices}
  20. Keyword [OrderID] found in SQL for {Invoices Filter}
  21. Keyword [OrderID] found in SQL for {Order Details Extended}
  22. Keyword [OrderID] found in SQL for {Order Subtotals}
  23. Keyword [OrderID] found in SQL for {Orders Qry}
  24. Keyword [OrderID] found in SQL for {Product Sales for 1997}
  25. Keyword [OrderID] found in SQL for {Quarterly Orders by Product}
  26. Keyword [OrderID] found in SQL for {Sales by Category}
  27. Keyword [OrderID] found in SQL for {Sales by Year}
  28. Keyword [OrderID] found in SQL for {Sales Totals by Amount}
  29. Keyword [OrderID] found in SQL for {Summary of Sales by Quarter}
  30. Keyword [OrderID] found in SQL for {Summary of Sales by Year}
  31. Keyword [ShippedDate] found in SQL for {Employee Sales by Country}
  32. Keyword [ShippedDate] found in SQL for {Invoices}
  33. Keyword [ShippedDate] found in SQL for {Orders Qry}
  34. Keyword [ShippedDate] found in SQL for {Product Sales for 1997}
  35. Keyword [ShippedDate] found in SQL for {Sales by Year}
  36. Keyword [ShippedDate] found in SQL for {Sales Totals by Amount}
  37. Keyword [ShippedDate] found in SQL for {Summary of Sales by Quarter}
  38. Keyword [ShippedDate] found in SQL for {Summary of Sales by Year}
P.S. - You can also easily add Replace capability into the code logic.
Dec 23 '08 #12
prn
254 Expert 100+
NeoPa and ADezii: Thank You!

In fact, with the Documenter's options set to include the SQL only and nothing for Fields and Indexes, the Documenter managed to create a buffer full of all 1245 queries in less than 20 minutes. I first failed to select "Nothing" for Fields and Indexes and it looked like it was going to run for a looooong time. Then, with the result in the active window, I was also able to export it (File > Export) to a text file (1.8 MB, 95,669 lines) and could search that.

Fortunately, the diagnostic strings for my current needs were "simple" strings, so I didn't need much search capability. This would make NeoPa's and ADezii's suggestions very attractive, and if I need to to something similar again, I'll certainly consider using the VBA solution. If I had needed real RE matching capabilities, it appears that I could still do that in vba, but it looks a bit more complicated. (Certainly not as straightforward as in Perl :) but doable.)

Thanks, guys, I'm saving a bookmark to this information for sure.

Paul
Dec 23 '08 #13
NeoPa
32,556 Expert Mod 16PB
Pleased to be able to help Paul.

Have a very Merry Christmas :)
Dec 23 '08 #14

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

Similar topics

3
by: screenwriter776 | last post by:
Hi, folks - Perhaps you could help me with a search form I am building. I have a table with a field in it. I want to return dates inside two parameters the user enters into a search form:...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
2
by: caine | last post by:
I'm doing a search application for my project. My code can prompt alert popup window when the user doesn't key in any keywords. However, if the user keys in any keywords, it juz return "Please...
14
by: Simon Gare | last post by:
Hi, have a search.asp page with results.asp page drawing data from an SQL db, problem is the user has to type the whole field value into the search box to retrieve the value on results.asp, what...
3
by: RoomfulExpress | last post by:
Here is the URL where the code is posted: http://www.roomfulexpress.com/newsite/search/response2.php I pulled this code from: <Link removed> The code as a whole seems to make sense to me,...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
5
by: th1982 | last post by:
HI All I have a search page' s result which view 3results/per page,but my "next" link to view next page is not working. Here is my code : <?php // Get the search variable from URL ...
3
by: Vincent SHAO | last post by:
Search engine have to record all of the query string. Now i have a search engine log which contains 10 milllion query strings, but almost of them are repeated, not more than 3 million of them are...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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,...
0
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...

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.