D
Don Hyams
Query to find records containing all words
I have a rather sloppy freeform Access 97 table that was imported from
an old DOS-based database. The information is haphazardly spread
among different fields in each record. Unfortunately, optimizing it
(cleaning it up) would be a insanely huge project. This means that
any searches must check all fields in each record.
Here's a simplified version of the current query where the criteria is
entered in a textbox on a form:
SELECT DISTINCTROW tblData.Field1, tblData.Field2, tblData.Field3,
tblData.Field4
FROM tblData
WHERE (((tblData.Field1) Like "*" & [Forms]![frmSearch]![txtCriteria]
& "*")) OR (((tblData.Field2) Like "*" &
[Forms]![frmSearch]![txtCriteria] & "*")) OR (((tblData.Field3) Like
"*" & [Forms]![frmSearch]![txtCriteria] & "*")) OR (((tblData.Field4)
Like "*" & [Forms]![frmSearch]![txtCriteria] & "*"))
ORDER BY tblData.Field1
This works fine if only one word is in the search criteria. But if
multiple words are entered, they are treated as a phrase.
I need to be able to query all of the fields in each record in this
table and return records that contain multiple criteria. In effect,
treating each record as one long field.
For example, if the user types "George" in a search field, the query
should return all records that have "George" in ANY field.
If the user types "George Washington", the query should return all
records that have"George" in any field AND "Washington" in any field.
Any record that did not contain both words (looking through all
fields) would not be returned.
If the user types "George Washington Carver", the query should return
all records that have"George" in any field AND "Washington" in any
field AND "Carver" in any field. Any record that did not contain all
three words (looking through all fields) would not be returned.
ETC, ETC...
I realize I'll probably have to limit the number of words that can be
used in a query in this manner, although it would be nice not to have
that restriction.
As part of the solution I presume I'll have to have multiple keyword
search fields or set up some kind of parsing on one search field.
Surely this isn't a unique problem. Thanks in advance for helping me
avoid reinventing the wheel.
--Don
I have a rather sloppy freeform Access 97 table that was imported from
an old DOS-based database. The information is haphazardly spread
among different fields in each record. Unfortunately, optimizing it
(cleaning it up) would be a insanely huge project. This means that
any searches must check all fields in each record.
Here's a simplified version of the current query where the criteria is
entered in a textbox on a form:
SELECT DISTINCTROW tblData.Field1, tblData.Field2, tblData.Field3,
tblData.Field4
FROM tblData
WHERE (((tblData.Field1) Like "*" & [Forms]![frmSearch]![txtCriteria]
& "*")) OR (((tblData.Field2) Like "*" &
[Forms]![frmSearch]![txtCriteria] & "*")) OR (((tblData.Field3) Like
"*" & [Forms]![frmSearch]![txtCriteria] & "*")) OR (((tblData.Field4)
Like "*" & [Forms]![frmSearch]![txtCriteria] & "*"))
ORDER BY tblData.Field1
This works fine if only one word is in the search criteria. But if
multiple words are entered, they are treated as a phrase.
I need to be able to query all of the fields in each record in this
table and return records that contain multiple criteria. In effect,
treating each record as one long field.
For example, if the user types "George" in a search field, the query
should return all records that have "George" in ANY field.
If the user types "George Washington", the query should return all
records that have"George" in any field AND "Washington" in any field.
Any record that did not contain both words (looking through all
fields) would not be returned.
If the user types "George Washington Carver", the query should return
all records that have"George" in any field AND "Washington" in any
field AND "Carver" in any field. Any record that did not contain all
three words (looking through all fields) would not be returned.
ETC, ETC...
I realize I'll probably have to limit the number of words that can be
used in a query in this manner, although it would be nice not to have
that restriction.
As part of the solution I presume I'll have to have multiple keyword
search fields or set up some kind of parsing on one search field.
Surely this isn't a unique problem. Thanks in advance for helping me
avoid reinventing the wheel.
--Don