Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search all tables in Acces DB 1

Status
Not open for further replies.

johnny45

Technical User
Nov 8, 2006
136
CA
I need to search for a record but I dont know the table name or field. Is there a way to do this ?
 
Do you mean you want to search for a specific value in a table, but you don't know the field name or which table it appears in?

If so the following function should do you want. Be aware that it may well take a while to run dependent on the size of your database.

Code:
Public Function FindVal(ByVal varSearchVal As Variant)
    Dim ThisDB As DAO.Database
    Dim TDef As DAO.TableDef
    Dim rstSearchMe As DAO.Recordset
    Dim MyField As DAO.Field
    Dim lngRecordNumber As Long
    Dim strResults As String
    
    Set ThisDB = CurrentDb
    
    For Each TDef In ThisDB.TableDefs
        If Left$(TDef.Name, 4) <> "MSys" Then
            lngRecordNumber = 1
            Set rstSearchMe = ThisDB.OpenRecordset(TDef.Name, dbOpenSnapshot)
            
            With rstSearchMe
                .MoveFirst
                Do While Not .EOF
                    For Each MyField In rstSearchMe.Fields
                        If rstSearchMe(MyField.Name).Value = varSearchVal Then
                            strResults = strResults & "Value found in table " & TDef.Name & " in field " & MyField.Name & " at record number " & lngRecordNumber & "." & vbCrLf
                        End If
                    Next MyField
                    .MoveNext
                    lngRecordNumber = lngRecordNumber + 1
                Loop
            End With
        End If
    Next TDef
    
    FindVal = strResults
End Function

Ed Metcalfe.

Please do not feed the trolls.....
 
I need to search for a record but I dont know the table name or field
It's a joke ?
Please, read carefully this: FAQ181-2886
 
Another case for the new version Redmond is reportedly working on: Access ESP!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Well if it is a joke thanks a bunch to the poster for wasting my time writing that code! lol.

Ed Metcalfe.

Please do not feed the trolls.....
 
How are ya johnny45 . . .

If a form have a look at its [blue]RecordSource[/blue] property!

. . . and do give a serious look at the FAQ provided by [blue]PHV![/blue]

Calvin.gif
See Ya! . . . . . .
 
Thank you very much for all the posts.... grin:)
Well here is the situation, started working with an accounting sofware...and in order to "manipulate" the DB outsite of the application itself one needs to understand how records are written and were....I just though that by being able to search across the DB I could track the transactions so as to know which tables are affected .....so rather than key in the using cumbersome interface I could import my inventory count.

Thank you very much Ed2020 for the code, will give it a try on monday . :)
 
johnny45 . . .

Just a side note: To get great answers be sure to have a serious look at FAQ219-2884 or FAQ181-2886. One of them already stated by [blue]PHV![/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
johnny45 said:
...and in order to "manipulate" the DB outsite of the application itself one needs to understand how records are written and were....I just though that by being able to search across the DB I could track the transactions so as to know which tables are affected .....so rather than key in the using cumbersome interface I could import my inventory count.
I would advise against directly inserting into another application's database, especially an accounting system. There's a good chance you will not be able to discover all the business rules of the application. You could end up wrecking the system.
Try to find out if the application has any API's for third party developers instead.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top