Results 1 to 8 of 8

Thread: Searching VBA

  1. #1
    Join Date
    Aug 2003
    Posts
    29

    Smile Unanswered: Searching VBA

    I would like to search the entire project (all the VBA Code) for all instances of "OpenReport" and capture them with debug.print.

    Anyone have a suggestion?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Select the Current Project option.

  3. #3
    Join Date
    Aug 2003
    Posts
    29

    Searching VBA

    I'm sorry my question was not detailed.

    I want to use a VBA code module to do this, not the Find feature.
    That is, I want to parse through all the VBA code and when I find an "OpenReport" statement I want to capture the name of the procedure which contains the statement to a file or table. I need to do this for both forms and reports.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Go through all your VBA code and locate the OpenForm, OpenTable, or OpenReport statements. Above each statement place the DebugPrint:

    Debug.Print "OpenReport - Report name MyReport"
    DoCmd.OpenReport "MyReport", acPreview


  5. #5
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147
    You want code that looks at code to find occurences of when a specific word is used ?

  6. #6
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147

    OK I came up with this..

    Hmmmm I was thinking about that, and wondered if it was possible to search VBA using VBA and came up with this.


    Dim M As AccessObject, dbase As Object, MD As Module
    Dim lngStartLine As Long, lngBodyLine As Long, Find_This As String
    Dim lngCount As Long, lngEndProc As Long, PR As String, A

    Set dbase = Application.CurrentProject

    Find_This = "Docmd" '<--- text you are looking for

    For Each M In dbase.AllModules

    If M.Name <> "module1" Then '<---name of my module - Put your module name here

    DoCmd.OpenModule (M.Name)

    Set MD = Modules(M.Name)

    DoCmd.OpenModule M.Name

    How_Many_Lines = MD.CountOfLines

    For A = 3 To How_Many_Lines

    If Left(MD.Lines(A, 1), 3) = "sub" Then PR = MD.Lines(A, 1)

    If InStr(1, MD.Lines(A, 1), Find_This, vbTextCompare) Then

    Debug.Print "< Procedure > "; PR; "< Line number > "; A; " < Code > "; Trim(MD.Lines(A, 1))

    End If

    Next

    DoCmd.Close acModule, MD

    End If

    Next M


    Please note where I put your module name, I did this, as module1 was where this procedure was stored, if I didnt put this in, it would shut down the window I was running it in! If you remove it, then don't forget to take out that very last 'end if'

    Does this answer part of problem ?? Still working on the insert bit...

    Ken

  7. #7
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147

    solved

    Edit the code in the middle with this:


    If Left(MD.Lines(A, 1), 3) = "sub" Then PR = MD.Lines(A, 1)

    If InStr(1, MD.Lines(A, 1), Find_This, vbTextCompare) Then

    MD.InsertLines A, "Debug.Print " & Trim(MD.Lines(A, 1))

    A = A + 1

    Debug.Print "< Procedure > "; PR; "< Line number > "; A; " < Code > "; Trim(MD.Lines(A, 1))

    End If

    Next


    Bit of a mind bender problem !!

    Marks out of 10 for my help ??

    Ken

  8. #8
    Join Date
    Aug 2003
    Posts
    29
    Hi Ken;

    Thanks for your suggestion. I give you 9.5 marks out of ten!

    However your suggestion is not exactly what I'm looking for.

    Your suggestion will find the occurances of a word in the Modules and thats great. But I'm also looking for the occurances of a word in the code behind all the forms and reports.


    jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •