Searching all queries for a field name

J

JP_Denver

Is there a way to search through all of my queries to see which ones are referencing a specific field in a specific table
I need to make some changes ans want to make sure I don't miss any queries that the field is used in.
 
N

Nikos Yannacopoulos

JP,

The following piece of code will give yopu what you want, just change to
field name to whatever you are looking for:

Sub queries_containing_field()
vFiledName = "YourFieldNameHere"
For Each qry In CurrentDb.QueryDefs
For Each fld In qry.Fields
If fld.Name = vFieldName Then
msg = msg & qry.Name & Chr(10)
Exit For
End If
Next
Next
MsgBox msg ' or debug.print msg, or....
End Sub

HTH,
Nikos

JP_Denver said:
Is there a way to search through all of my queries to see which ones are
referencing a specific field in a specific table?
I need to make some changes ans want to make sure I don't miss any queries
that the field is used in.
 
B

Bas Cost Budde

.... and you don't have the field somewhere in an expression on a form or
report field?
referencing a specific field in a specific table?

If you just want an indication of whether a field is referred in a
query, you can examine the SQL property (AIR CODE):

dim qd as querydef
dim db as database
set db=currentdb
for each qd in db.querydefs
if instr(qd.sql,cFieldName)>0 then debug.print qd.name
next
set db=nothing
 
Top