TheBrenda said:
I am not looking for something to release to the client. This is a
programmers' tool. Looking for a form that will search for the selected
text
across all tables in my Access database (or selected tables). I am tired
of
looking for for something in multiple tables. Does anyone have such a tool
that they can share?
I find this in my "test and debug" module:
'------ start of code -------
Sub SearchForData(ValueSought As Variant)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim intValueType As Integer
Dim intFld As Integer
Dim blnTestField As Boolean
Dim aintFieldsToCheck(255) As Integer
Dim intNFields As Integer
Dim I As Integer
intValueType = VarType(ValueSought)
Select Case intValueType
Case vbNull, vbEmpty, vbArray, vbError, vbObject, _
vbDataObject, vbUserDefinedType
Err.Raise 5, , "Invalid data type for search"
End Select
Debug.Print "*** Searching database for "; ValueSought; " ***"
Set db = CurrentDb
For Each tdf In db.TableDefs
If Not (tdf.Name Like "MSys*") Then
Set rs = tdf.OpenRecordset(dbOpenSnapshot)
If rs.EOF = False Then
' Before processing the actual records, make a list of
' all the fields in this recordset of the appropriate type.
intNFields = 0
For I = 0 To rs.Fields.Count - 1
blnTestField = False
Select Case intValueType
Case vbString
Select Case rs.Fields(I).Type
Case dbText, dbMemo, dbChar
blnTestField = True
End Select
Case vbDate
Select Case rs.Fields(I).Type
Case dbDate, dbTime
blnTestField = True
End Select
Case vbBoolean
Select Case rs.Fields(I).Type
Case dbBoolean
End Select
Case Else
Select Case rs.Fields(I).Type
Case dbLong, dbInteger, dbDouble, dbSingle,
dbCurrency, _
dbByte, dbFloat, dbDecimal, dbNumeric
blnTestField = True
End Select
End Select
If blnTestField Then
aintFieldsToCheck(intNFields) = I
intNFields = intNFields + 1
End If
Next I
' Were there any qualifying fields?
If intNFields > 0 Then
With rs
Do Until .EOF
For I = 0 To (intNFields - 1)
intFld = aintFieldsToCheck(I)
If .Fields(intFld).Value = ValueSought Then
Debug.Print tdf.Name; " : ";
For Each fld In rs.Fields
Debug.Print , fld.Name; "=";
fld.Value
Next fld
Debug.Print
End If
Next I
.MoveNext
Loop
End With
End If
End If
rs.Close
Set rs = Nothing
End If
Next tdf
Debug.Print "*** Search Complete ***"
Set db = Nothing
End Sub
'------ end of code -------
I don't even recall how well it works, or if it has been thoroughly tested,
but you're welcome to use it if it helps.