vivi11130704
vivi11130704

Reputation: 451

How to check if a Keyword exists in an Access Query

My question is quite simple but my access database have multiple queries and I want to write an automate process to check if certain keyword exists in any of the queries. This automate process can either be a query or a VBA. Can someone please give me an idea where to start?

Thanks in advance!

Upvotes: 0

Views: 164

Answers (2)

wazz
wazz

Reputation: 5058

@vivi Use @Don-George's answer, but if you just want the query's name(s), replace the middle part:

If InStr(S, F_string) > 0 Then
    Debug.Print QD.Name
End If

Upvotes: 1

Don George
Don George

Reputation: 1328

I wrote this for a completely different purpose - but it may give you a place to start. It lookps through all queries, looking for a specific string and replacing it with a different one.

Function MassChange(F_string, T_string)
Dim DB As Database
Dim QD As QueryDef
Dim S As String

Set DB = CurrentDb
For Each QD In DB.QueryDefs
    S = QD.SQL
    If InStr(S, F_string) > 0 Then
        S = Replace(S, F_string, T_string)
        QD.SQL = S
    End If
Next QD
MsgBox ("done")

End Function

Upvotes: 2

Related Questions