Hi guys,
I am looking for some good help. What a would like to do is create a search function that will look through one entire tabel filled with IP adresses. This table exisit out of multiple columns.
I would like the search to go trough the entire table and in the end list me all the values found.
I already tried it via a query, but I could that one only working for one column. I also tried the follwing module but could get it to do what I would like either.
Option Compare Database
Sub FullLIKESearch()
Dim rs As Recordset, tdf As TableDef, fld As Field, strSearch As String, iResp As Integer
'Search EVERY TABLE, EVERY FIELD in a database for a text string (substring, really)
strSearch = "0" 'this will be parameterized in the sub definition
For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 4) = "MSys" Then GoTo lblNextTable
On Error GoTo errFullSearch1
Set rs = CurrentDb.OpenRecordset(tdf.Name, dbOpenDynaset)
On Error GoTo 0
rs.MoveLast
If rs.RecordCount * rs.Fields.Count > CLng(300000) Then
iResp = MsgBox("Okay to do " & rs.Fields.Count & " fields for " _
& rs.RecordCount & " records in " & tdf.Name & " ?", vbYesNo)
If iResp <> vbYes Then Debug.Print "skipped " & tdf.Name: GoTo lblNextTable
End If
'Debug.Print tdf.Name
For Each fld In rs.Fields
'Debug.Print "field " & fld.Name
rs.FindFirst "[" & fld.Name & "] LIKE " & "'*" & strSearch & "*'"
'rs.FindFirst "[" & fld.Name & "] = " & "'*" & strSearch & "*'"
If Not rs.NoMatch Then Debug.Print tdf.Name, fld.Name, strSearch: GoTo lblNextTable
Next fld
lblNextTable:
Next tdf
Debug.Print "DONE"
rs.Close: Set rs = Nothing
Exit Sub
errFullSearch1:
Debug.Print "problem opening " & tdf.Name
Resume lblNextTable
End Sub
Any help would be greatly appreciated...
Thanks in advance
Kindest regards
Henri van den Heuvel
I am looking for some good help. What a would like to do is create a search function that will look through one entire tabel filled with IP adresses. This table exisit out of multiple columns.
I would like the search to go trough the entire table and in the end list me all the values found.
I already tried it via a query, but I could that one only working for one column. I also tried the follwing module but could get it to do what I would like either.
Option Compare Database
Sub FullLIKESearch()
Dim rs As Recordset, tdf As TableDef, fld As Field, strSearch As String, iResp As Integer
'Search EVERY TABLE, EVERY FIELD in a database for a text string (substring, really)
strSearch = "0" 'this will be parameterized in the sub definition
For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 4) = "MSys" Then GoTo lblNextTable
On Error GoTo errFullSearch1
Set rs = CurrentDb.OpenRecordset(tdf.Name, dbOpenDynaset)
On Error GoTo 0
rs.MoveLast
If rs.RecordCount * rs.Fields.Count > CLng(300000) Then
iResp = MsgBox("Okay to do " & rs.Fields.Count & " fields for " _
& rs.RecordCount & " records in " & tdf.Name & " ?", vbYesNo)
If iResp <> vbYes Then Debug.Print "skipped " & tdf.Name: GoTo lblNextTable
End If
'Debug.Print tdf.Name
For Each fld In rs.Fields
'Debug.Print "field " & fld.Name
rs.FindFirst "[" & fld.Name & "] LIKE " & "'*" & strSearch & "*'"
'rs.FindFirst "[" & fld.Name & "] = " & "'*" & strSearch & "*'"
If Not rs.NoMatch Then Debug.Print tdf.Name, fld.Name, strSearch: GoTo lblNextTable
Next fld
lblNextTable:
Next tdf
Debug.Print "DONE"
rs.Close: Set rs = Nothing
Exit Sub
errFullSearch1:
Debug.Print "problem opening " & tdf.Name
Resume lblNextTable
End Sub
Any help would be greatly appreciated...
Thanks in advance
Kindest regards
Henri van den Heuvel