By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

How to get text from ms-access module in remote db?

P: n/a
I need to scan a couple of hundred databases in several directories to
locate all code that uses a particular function, but cannot figure out
how to read the Form or Module text itself.

I am able to locate, then connect to the databases, and have figured
out how to get the Form and Module names easy enough using the
documents collection of each of the Form and Module containers, but
how do I actually read the code to find out which contain the function
code I am searching?

Is there any more direct way to read it rather than using
Application.SaveAsText?
----------------------------
set db = OpenDatabase([Database path and name])
for i = 0 to db.Containers("Modules").Documents.Count
oDoc = db.Containers("Modules").Documents(i)
sName = oDoc.Name '- Wonks so far ...
sText = oDoc.???? How do I read the actual text (code) in each
module or form?
---------------------------
Thanks in Advance - jfro
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The Containers Collection and Documents class for the Modules objects
contains no interface to the VBA code. If you want to access the module
code programmatically, then you'll need to use the DoCmd.OpenModule method
from the Access Application object used to open the remote database, so you
don't need to use the OpenDatabase method in your code below, either.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"JimF" <jf****@marinusdigital.com> wrote in message
news:56**************************@posting.google.c om...
I need to scan a couple of hundred databases in several directories to
locate all code that uses a particular function, but cannot figure out
how to read the Form or Module text itself.

I am able to locate, then connect to the databases, and have figured
out how to get the Form and Module names easy enough using the
documents collection of each of the Form and Module containers, but
how do I actually read the code to find out which contain the function
code I am searching?

Is there any more direct way to read it rather than using
Application.SaveAsText?
----------------------------
set db = OpenDatabase([Database path and name])
for i = 0 to db.Containers("Modules").Documents.Count
oDoc = db.Containers("Modules").Documents(i)
sName = oDoc.Name '- Wonks so far ...
sText = oDoc.???? How do I read the actual text (code) in each
module or form?
---------------------------
Thanks in Advance - jfro

Nov 13 '05 #2

P: n/a

Quick bit of code so you'll need to test etc. but it should get you started

Sub IterateModules(DBName As String)
Dim oApp As Access.Application
Dim db As DAO.Database
Dim oDoc As DAO.Document
Dim oMod As Access.Module
Dim sText As String

Set oApp = New Access.Application

oApp.OpenCurrentDatabase DBName

Set db = oApp.CurrentDb

For Each oDoc In db.Containers("Modules").Documents
oApp.DoCmd.OpenModule oDoc.Name

Set oMod = oApp.Modules(oDoc.Name)
With oMod
sText = .Lines(1, .CountOfLines)
End With

' do stuff with stext
Next

Set oDoc = Nothing
Set oMod = Nothing
Set db = Nothing
oApp.Quit acQuitSaveNone
Set oApp = Nothing

End Sub
--
Terry Kreft
MVP Microsoft Access
"JimF" <jf****@marinusdigital.com> wrote in message
news:56**************************@posting.google.c om...
I need to scan a couple of hundred databases in several directories to
locate all code that uses a particular function, but cannot figure out
how to read the Form or Module text itself.

I am able to locate, then connect to the databases, and have figured
out how to get the Form and Module names easy enough using the
documents collection of each of the Form and Module containers, but
how do I actually read the code to find out which contain the function
code I am searching?

Is there any more direct way to read it rather than using
Application.SaveAsText?
----------------------------
set db = OpenDatabase([Database path and name])
for i = 0 to db.Containers("Modules").Documents.Count
oDoc = db.Containers("Modules").Documents(i)
sName = oDoc.Name '- Wonks so far ...
sText = oDoc.???? How do I read the actual text (code) in each
module or form?
---------------------------
Thanks in Advance - jfro

Nov 13 '05 #3

P: n/a
> Quick bit of code so you'll need to test etc. but it should get you started

Terry, Gunny ... exactly what I needed. Thanks! Jim
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.