Is there any sort of limitation in DAO.Recordset objects that would prevent me from searching across multiple columns for a match with code along the lines of this code?
On SQL Server I have used this capability thusly:
Should I have success with the same type of SQL query WHERE clause using a DAO.Recordset created with Me.RecordsetClone?
Would the same UI be possible that it would jump to the next find hit, no matter which of the columns the hit was found in?
Code:
Dim strFindInCol
Dim strWhereClause
Dim daoRS As DAO.Recordset
'Find out which column is currently being sorted by
If InStr(1, strCurrentSort, Chr(32), vbTextCompare) = 0 Then
strFindInCol = strCurrentSort
Else
strFindInCol = Mid(strCurrentSort, 1, InStr(1, strCurrentSort, Chr(32), vbTextCompare) - 1)
End If
'Determine if the col is one we support string matches for
'If not, then exit
If Not (strFindInCol = "partnumber") And _
Not (strFindInCol = "title") Then
'Blank the search field
Me.fldFind.Value = vbNullString
'Debug.Print "Wrong Col: " & strFindInCol
GoTo Exit_FindRecord
End If
'Atttach to the Form's record set
Set daoRS = Me.RecordsetClone
[COLOR=Blue][B]strWhereClause = "[" & strFindInCol & "] LIKE " & Chr(34) & "*" & strFindText & "*" & Chr(34)[/B][/COLOR]
If flgFindNext = True Then
daoRS.FindNext (strWhereClause)
Else
daoRS.FindFirst (strWhereClause)
End If
'If we could find no match
If daoRS.NoMatch Then
Me.fldFind.BackColor = vbRed
'Debug.Print "NoMatch"
'Else jump to it
Else
Me.Bookmark = daoRS.Bookmark
With Me.fldFind
.BackColor = vbWhite
.SetFocus
.SelStart = Len(strFindText)
End With
'Debug.Print "Match"
End If
'Clean up the connection to the database
Set daoRS = Nothing
Code:
-- This variable must be +2 to what ever the input arg length is
DECLARE @qrysearchstring varchar(52)
SET @qrysearchstring = '%' + @searchstring + '%'
SELECT [aoes].[id],
[aoes].[stationname],
[aoes].[mnfm],
[aoes].[loto]
FROM [dbo].[aoestation] AS [aoes]
[B][COLOR=Blue]WHERE [aoes].[stationname] LIKE @qrysearchstring
OR [aoes].[mnfm] LIKE @qrysearchstring
OR [aoes].[loto] LIKE @qrysearchstring;[/COLOR][/B]
Would the same UI be possible that it would jump to the next find hit, no matter which of the columns the hit was found in?