Reputation: 1167
My team has many Access database files that use VB in their form classes to call stored procedures.
I want to be able to search the Access Class Objects in these accdb files for the stored procedure names, but Microsoft Visual Basic for Applications doesn't seem to support searching all the class definitions at once.
Is there a way to search all the Access Class Objects in a accdb file for a string?
Upvotes: 0
Views: 1001
Reputation: 1167
The VBA solution didn't print the CodeBehindForm section for me, but I did get success using the Interop libraries.
using Microsoft.Office.Interop.Access;
using System;
namespace AccessExporter
{
class Program
{
static void Main(string[] args)
{
ApplicationClass app = new ApplicationClass();
String fileName = @"C:\AccessFile.accdb";
app.Visible = false;
app.OpenCurrentDatabase(fileName);
foreach (AccessObject obj in app.CurrentProject.AllForms)
{
Console.WriteLine(obj.Name);
app.SaveAsText(AcObjectType.acForm, obj.Name, String.Format(@"C:\{0}.txt", obj.Name));
}
app.CloseCurrentDatabase();
}
}
}
Upvotes: 1
Reputation: 123829
You could use the hidden Application.SaveAsText
VBA method to dump the forms to text files and then use your favorite searching tool (something like grepWin, perhaps) to rummage through the files looking for those SP names. The code to dump the forms would be something like this:
Sub DumpFormsToText()
Dim frm As Variant
Const OutFolder = "C:\__tmp\FormDump\"
For Each frm In Application.CurrentProject.AllForms
Application.SaveAsText acForm, frm.Name, OutFolder & frm.Name & ".txt"
Next
Set frm = Nothing
End Sub
Upvotes: 1