D
Dale Fye
I'm working on my own version of a search and replace utility. I know Rick
Fisher has one, but lets just call this an exercise in frustration.
In this process, I want to pass a string to a subroutine, that will check
the SQL statements of all the queries in my database (I know the code below
won't accomplish this, but I intend to write another routine to analyze
query strings that I find in Form RecordSources or Control RowSource
properties, although I try to make sure that all of these are saved
queries).
As part of that subroutine, I want to pass an argument indicating whether to
look for an "exact match" or a "contains". I would like to use the Like
operator in this comparison, but cannot figure out the correct syntax.
Additionally, if searching for an exact match I want to check for a variety
of characters preceeding and following the search string (to account for the
fact that the value may be surrounded by a variety of characters (!._[ ] ,
etc.
I've used Like frequently in SQL queries, but have only recently realized
that it is available as a VBA operator, and have not found many posts that
discuss its use. Unfortunately, I have been unable to get the Like operator
to do what I want, and have resorted to using the instr( ) function as a
simple comparison.
The code looks similar to:
Private Sub SearchQueries(SearchFor as String, Optional ExactMatch as
boolean = True)
Dim qdf as dao.querydef
For each qdf in currentdb.querydefs
If ExactMatch then
IF qdf.SQL Like "*[!._(]" & SearchFor & "[!._)]*" Then
'do something
endif
else
IF qdf.SQL Like "*" & SearchFor & "*" Then
'do something
endif
endif
Next
End Sub
1. This seems to work if I replace the stuff to the right of the Like with
a literal value "*Activity_ID*", but not when I try to append wildcard
characters to a variable. What am I doing wrong?
2. Do I need to write a separate Like statement to account for no leading
characters or no trailing characters in the Exact Match case?
3. How do I add brackets "[" or "]" into the wildcard search strings?
Thanks for any help
Dale
Fisher has one, but lets just call this an exercise in frustration.
In this process, I want to pass a string to a subroutine, that will check
the SQL statements of all the queries in my database (I know the code below
won't accomplish this, but I intend to write another routine to analyze
query strings that I find in Form RecordSources or Control RowSource
properties, although I try to make sure that all of these are saved
queries).
As part of that subroutine, I want to pass an argument indicating whether to
look for an "exact match" or a "contains". I would like to use the Like
operator in this comparison, but cannot figure out the correct syntax.
Additionally, if searching for an exact match I want to check for a variety
of characters preceeding and following the search string (to account for the
fact that the value may be surrounded by a variety of characters (!._[ ] ,
etc.
I've used Like frequently in SQL queries, but have only recently realized
that it is available as a VBA operator, and have not found many posts that
discuss its use. Unfortunately, I have been unable to get the Like operator
to do what I want, and have resorted to using the instr( ) function as a
simple comparison.
The code looks similar to:
Private Sub SearchQueries(SearchFor as String, Optional ExactMatch as
boolean = True)
Dim qdf as dao.querydef
For each qdf in currentdb.querydefs
If ExactMatch then
IF qdf.SQL Like "*[!._(]" & SearchFor & "[!._)]*" Then
'do something
endif
else
IF qdf.SQL Like "*" & SearchFor & "*" Then
'do something
endif
endif
Next
End Sub
1. This seems to work if I replace the stuff to the right of the Like with
a literal value "*Activity_ID*", but not when I try to append wildcard
characters to a variable. What am I doing wrong?
2. Do I need to write a separate Like statement to account for no leading
characters or no trailing characters in the Exact Match case?
3. How do I add brackets "[" or "]" into the wildcard search strings?
Thanks for any help
Dale