How to count number of MSGBOX

PiedPiper70

Registered User.
Local time
Today, 08:34
Joined
Oct 21, 2012
Messages
115
It sounds odd I know, but as part of a planned redesign of a largish system I would like to determine how many occurrences there are in my code (160K lines) of the MsgBox function. Anyone have any idea how I can do that please?

Thanks
Dave
 
Download the free v-tools and do a search: it will give you an inkling
 
Is it safe to install???
 
Try this
Call CountOccurence("Msgbox")

Code:
 Sub CountOccurence(strSearchString As String)
   Dim strName As String, strMdlText As String
   Dim i As Integer, n As Integer, intCount As Integer
   Dim lngLineCount As Long
   
   'strSearchString = "Msgbox"
   
   intCount = 0
   For i = 0 To CurrentProject.AllModules.Count - 1
      strName = CurrentProject.AllModules(i).Name
   
      lngLineCount = Access.Modules(strName).CountOfLines
      strMdlText = Access.Modules(strName).Lines(1, lngLineCount)
      
      n = 0
      n = InStr(n + 1, strMdlText, strSearchString)
      Do While n > 0
         intCount = intCount + 1
         n = InStr(n + 1, strMdlText, strSearchString)
      Loop
   Next
      
   Debug.Print intCount
  
 End Sub
 
I don't think this routine handles modules behind forms.

I'm trying it and it fails because a form is not open.
 
To include forms, loop through the forms container and open/close each form at start/end of loop.
 
All this complexity! Just use the Replace function in the VBA Editor.

Set it up with:
Search: Current Project; Find What: Msgbox; Replace With: MsgBox.

Hit Replace All and it will do the "change" and return the count.
 
Thanks to all for suggestions, but particularly to Galaxiom for coming up with the simple answer. By the way my count was 2619 !!!
 

Users who are viewing this thread

Back
Top Bottom