Is a query a record source for any report in my db?

G

Guest

I have tons of reports and queries in my db, how can I quickly check if a
query is the record source for any report in the db? I'm thinking there may
be something like 'trace dependents' in Excel but I haven't found it.
 
D

Dirk Goldgar

AC said:
I have tons of reports and queries in my db, how can I quickly check
if a query is the record source for any report in the db? I'm
thinking there may be something like 'trace dependents' in Excel but
I haven't found it.

Here's some quickie code that will do something very like what you ask:

'----- start of code -----
Sub SearchReportRecordSources(strSought As String)

' Search the recordsources of all reports
' for the specified string.

On Error GoTo Err_SearchReportRecordSources

Dim db As DAO.Database
Dim doc As DAO.Document
Dim rpt As Report

Dim varTest As Variant
Dim lngReportCount As Long
Dim lngFoundCount As Long

Debug.Print "*** Beginning search ..."

Set db = CurrentDb
For Each doc In db.Containers("Reports").Documents
DoCmd.OpenReport doc.Name, acDesign, _
WindowMode:=acHidden
Set rpt = Reports(doc.Name)
With rpt
lngReportCount = lngReportCount + 1
If InStr(.RecordSource, strSought) Then
Debug.Print "Report " & .Name & _
" RecordSource: " & .RecordSource
lngFoundCount = lngFoundCount + 1
End If
DoCmd.Close acReport, .Name
End With
Set rpt = Nothing
Next doc

Exit_SearchReportRecordSources:
Set doc = Nothing
Set db = Nothing
Debug.Print "*** Searched " & lngReportCount & _
" reports, found " & _
lngFoundCount & " occurrences."
Exit Sub

Err_SearchReportRecordSources:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_SearchReportRecordSources

End Sub
'----- end of code -----

Note that, as written, it searches for a particular string *within* the
recordsource, so if you search for "qryA", it will turn up reports that
use "qryA", "qryAB", "qryABC", and so on. You could modify it easily to
only find exact matches.
 
J

John Vinson

I have tons of reports and queries in my db, how can I quickly check if a
query is the record source for any report in the db? I'm thinking there may
be something like 'trace dependents' in Excel but I haven't found it.

There are some good third-party tools to track down dependencies and
obscure references; remember, the query might be the Rowsource of a
combo box upon which the report depends, or a Report query might be
based on another query!

Free:
http://www3.bc.sympatico.ca/starthere/findandreplace
Find and Replace: http://www.rickworld.com
Speed Ferret: http://www.moshannon.com
Total Access Analyzer: http://www.fmsinc.com


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top