Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text-search in properties Access objects

Is there a way in Access to search for a certain text in object properties and so on? Just not only in the VBA source code.

I'm asking this because if I change for example the name of a field in a table I've to check a lot of object properties (Record Source, Control Source, Order By, ...). This can be done by trail-and-error or by checking all properties of each control of the forms, but that takes a lot of time.

One option is the Find and Replace tool (nice tool!), but it's a bit of overkill for me. I don't need a text replace (only 'find') and it's 37 dollar for a tool I'll only use a few times a year.

Other suggestions?

like image 570
waanders Avatar asked Jun 20 '11 09:06

waanders


2 Answers

There is something I often use to find out where some function or query may be hidding somewhere unexpected (in a bound control's RowSource of within a sub-query for instance).

I use an undocumented feature to export all Access objects as raw text files.
Using a text editor that can search within files recursively under a folder(like the free Notepad++ for instance) I am then confident that I find all occurrences, however buried, of a particular string.

The Code for exporting all objects includes my IsBlank() function:

'====================================================================
' Name:    DocDatabase
' Purpose: Documents the database to a series of text files
' From:    http://www.datastrat.com/Code/DocDatabase.txt
' Author:  Arvin Meyer
' Date:    June 02, 1999
' Comment: Uses the undocumented [Application.SaveAsText] syntax
'          To reload use the syntax [Application.LoadFromText]
'          Modified to set a reference to DAO 8/22/2005
'          Modified by Renaud Bompuis to export Queries as proper SQL
'====================================================================
Public Sub DocDatabase(Optional path As Variant = Null)
    If IsBlank(path) Then
        path = Application.CurrentProject.path & "\" & Application.CurrentProject.Name & " - exploded view\"
    End If

    On Error Resume Next
    MkDir path 
    MkDir path & "\Forms\"
    MkDir path & "\Queries\"
    MkDir path & "\Queries(SQL)\"
    MkDir path & "\Reports\"
    MkDir path & "\Modules\"
    MkDir path & "\Scripts\"

    On Error GoTo Err_DocDatabase
    Dim dbs As DAO.Database
    Dim cnt As DAO.Container
    Dim doc As DAO.Document
    Dim i As Integer

    Set dbs = CurrentDb() ' use CurrentDb() to refresh Collections

    Set cnt = dbs.Containers("Forms")
    For Each doc In cnt.Documents
        Application.SaveAsText acForm, doc.Name, path & "\Forms\" & doc.Name & ".txt"
    Next doc

    Set cnt = dbs.Containers("Reports")
    For Each doc In cnt.Documents
        Application.SaveAsText acReport, doc.Name, path & "\Reports\" & doc.Name & ".txt"
    Next doc

    Set cnt = dbs.Containers("Scripts")
    For Each doc In cnt.Documents
        Application.SaveAsText acMacro, doc.Name, path & "\Scripts\" & doc.Name & ".txt"
    Next doc

    Set cnt = dbs.Containers("Modules")
    For Each doc In cnt.Documents
        Application.SaveAsText acModule, doc.Name, path & "\Modules\" & doc.Name & ".txt"
    Next doc

    Dim intfile As Long
    Dim filename as String
    For i = 0 To dbs.QueryDefs.count - 1
         Application.SaveAsText acQuery, dbs.QueryDefs(i).Name, path & "\Queries\" & dbs.QueryDefs(i).Name & ".txt"
         filename = path & "\Queries(SQL)\" & dbs.QueryDefs(i).Name & ".txt"
         intfile = FreeFile()
         Open filename For Output As #intfile
         Print #intfile, dbs.QueryDefs(i).sql
         Close #intfile
    Next i

    Set doc = Nothing
    Set cnt = Nothing
    Set dbs = Nothing

Exit_DocDatabase:
    Debug.Print "Done."
    Exit Sub

Err_DocDatabase:
    Select Case Err

    Case Else
        MsgBox Err.Description
        Resume Exit_DocDatabase
    End Select

End Sub

To use it, just call DocDatabase from the Immediate window in the Access IDE, it will create a set of directories under and 'Exploded View' folder that will contain all the files.

like image 156
Renaud Bompuis Avatar answered Oct 22 '22 05:10

Renaud Bompuis


Another option is to temporarily turn on the NAME AUTOCORRECT option. It's a badly implemented feature and can damage your database if left on for production deployment, but I very often use it when taking over an Access app created by somebody else in order convert it to use my naming conventions.

You basically turn it on, let it build the dependencies table, then make your changes. You can then walk the tree of dependencies to confirm that it got them all. When you're done, you turn it off.

However, it doesn't work for VBA code. But for changing field names and the like, it's pretty useful if used carefully.

like image 28
David-W-Fenton Avatar answered Oct 22 '22 03:10

David-W-Fenton