Private Sub btnSearch2_Click()
clearResults
DoCmd.Hourglass True
Dim myDb As DAO.Database
Dim i As Integer, j As Integer
Dim myTable As DAO.TableDef
Dim tableName As String
Dim booRstSch As Boolean
Dim numFields As Integer
Dim rstSearchTable As Recordset
Dim wherestr As String
Dim myfield As Field
Dim fldstr As String
Dim fldType
Dim blankpos
Set myDb = CurrentDb ' wrkJet.OpenDatabase(selectedFile, , True)
' Loop through all tables extracting the names
For i = 0 To myDb.TableDefs.Count - 1
Set myTable = myDb.TableDefs(i)
tableName = myTable.Name
If Left(tableName, 4) <> "MSys" And Left(tableName, 4) <> "usys" _
And Left(tableName, 1) <> "~" Then
' Now find the text fields
booRstSch = True
numFields = myTable.Fields.Count
Set rstSearchTable = myDb.OpenRecordset( _
tableName, dbOpenSnapshot)
wherestr = ""
For j = 0 To numFields - 1
Set myfield = myTable.Fields(j)
fldstr = myfield.Name
fldType = myfield.Type
If fldType = dbText Then
' Jet fieldnames can include unusual letters
blankpos = InStr(1, fldstr, " ") + _
InStr(1, fldstr, "#") + _
InStr(1, fldstr, "-") + _
InStr(1, fldstr, "/")
If blankpos > 1 Then
' Make sure blank spaces and other odd
' fieldname characters are handled correctly
fldstr = "[" & fldstr & "]"
End If
wherestr = wherestr & "(" & fldstr _
& " like '" & searchString & "'" & ")"
End If
Next j
' Now search for a string that matches
If Len(wherestr) > 1 Then
With rstSearchTable
[COLOR=Red] .FindFirst wherestr[/COLOR]
If .NoMatch Then
sqlfilternot = sqlfilternot & UCase(tableName) _
& " : Not Found" & vbCrLf & _
"Select * from " & tableName _
& " where " & wherestr & ";" _
& vbCrLf & vbCrLf
' GoTo nextTable
Else
sqlFilter = sqlFilter & UCase(tableName) _
& " : FOUND" & vbCrLf & "Select * from " _
& tableName & " where " & wherestr & ";" _
& vbCrLf & vbCrLf
End If
End With
End If
End If
Next i
DoCmd.Hourglass False
End Sub