|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Once in the past five years, I have been successful in updating an AS/400 file using an Access database. Unfortunately I cannot remember which PC it was on or who the client was. I therefore need to develop a program to search all the modules and class modules in each of the databases on each computer - which would be VERY tedious. As a (more interesting) alternative, does anyone know if the mechanism which displays the list of objects in the selected database when importing database objects is useable independently? If it is, then I can use a recursive directory search (cribbed from the VBScript help manual) to provide the file names, check the HasModule property of each form and search for an appropriate string.
Any other suggestions please?
Many thanks
Peter Kinsman
|
|
Peter Kinsman wrote:
[Quoted Text] >Once in the past five years, I have been successful in updating an AS/400 >file using an Access database. Unfortunately I cannot remember which PC it >was on or who the client was. I therefore need to develop a program to >search all the modules and class modules in each of the databases on each >computer - which would be VERY tedious. >As a (more interesting) alternative, does anyone know if the mechanism which >displays the list of objects in the selected database when importing >database objects is useable independently? If it is, then I can use a >recursive directory search (cribbed from the VBScript help manual) to >provide the file names, check the HasModule property of each form and search >for an appropriate string.
A messy problem, but not out of bounds. Once you get a loop to find all the mdb files, you can use OpenDatabase to get access to its objects.
While modules are objects, you said you want to find something inside the code modules. To do that you need to use the methods of the module object. Here's some vague air code to show the general idea:
Dim dbs As DAO.Database Dim doc As DAO.Document Dim lngLineNo As Long Set dbs = OpenDatabase(strPath) For Each doc In dbs.Containers("Modules").Documents DoCmd.OpenModule doc.Name lngLineNo =1 If doc.Find("string you are looking for", lngLineNo.1, _ doc.CountOfLines, 1000) Then Debug.Print Path, doc.Name, lngLineNo End If DoCmd.Close acModule, doc.Name, acSaveNo Next doc dbs.Close : Set dbs = Nothing
-- Marsh MVP [MS Access]
|
|
Marsh
Thanks for the suggestion. I had already tried something similar, but I had imported the modules one by one into the current database. One thing that worries me is whether opening the database will activate any Autoexec macros, which could have unwanted effects. Your use of the Find function is much more elegant than the code I had used. Presumably the names of any Class Modules are in Containers("Modules").Documents, so I do not have to check the HasModule property of each form. As it happens, I found the database that successfully updated the AS/400 file yesterday, and when I checked, there is a journal attached to the file in question - which was what I was really wanting to find.
Thanks again
Peter
"Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message news:ckm5h29257glngvql49srup2mo025mf0u7[ at ]4ax.com...
[Quoted Text] > Peter Kinsman wrote: > >>Once in the past five years, I have been successful in updating an AS/400 >>file using an Access database. Unfortunately I cannot remember which PC >>it >>was on or who the client was. I therefore need to develop a program to >>search all the modules and class modules in each of the databases on each >>computer - which would be VERY tedious. >>As a (more interesting) alternative, does anyone know if the mechanism >>which >>displays the list of objects in the selected database when importing >>database objects is useable independently? If it is, then I can use a >>recursive directory search (cribbed from the VBScript help manual) to >>provide the file names, check the HasModule property of each form and >>search >>for an appropriate string. > > > A messy problem, but not out of bounds. Once you get a loop > to find all the mdb files, you can use OpenDatabase to get > access to its objects. > > While modules are objects, you said you want to find > something inside the code modules. To do that you need to > use the methods of the module object. Here's some vague air > code to show the general idea: > > > Dim dbs As DAO.Database > Dim doc As DAO.Document > Dim lngLineNo As Long > Set dbs = OpenDatabase(strPath) > For Each doc In dbs.Containers("Modules").Documents > DoCmd.OpenModule doc.Name > lngLineNo =1 > If doc.Find("string you are looking for", lngLineNo.1, _ > doc.CountOfLines, 1000) Then > Debug.Print Path, doc.Name, lngLineNo > End If > DoCmd.Close acModule, doc.Name, acSaveNo > Next doc > dbs.Close : Set dbs = Nothing > > -- > Marsh > MVP [MS Access]
|
|
Glad this has become a moot issue.
To wrap things up, using OpenDatabase is not anywhere near the same as using automation to launch the other file. OpenDatabase will only provide access to the other database's objects, it will not execute any code or macros. The Modules collection does not include form or report class modules. You would need to loop through the Forms and Reports container documents to find those:
For Each doc In dbs.Containers("Forms").Documents DoCmd.OpenForm doc.Name, acDesign, _ WindowMode:=acHidden With Forms(doc.Name) If .HasModule Then . . . End If End With DoCmd.Close acForm, doc.Name, acSaveNo Next doc -- Marsh MVP [MS Access]
Peter Kinsman wrote:
[Quoted Text] >Thanks for the suggestion. I had already tried something similar, but I had >imported the modules one by one into the current database. One thing that >worries me is whether opening the database will activate any Autoexec >macros, which could have unwanted effects. Your use of the Find function is >much more elegant than the code I had used. Presumably the names of any >Class Modules are in Containers("Modules").Documents, so I do not have to >check the HasModule property of each form. >As it happens, I found the database that successfully updated the AS/400 >file yesterday, and when I checked, there is a journal attached to the file >in question - which was what I was really wanting to find. > > >"Marshall Barton" wrote >> Peter Kinsman wrote: >> >>>Once in the past five years, I have been successful in updating an AS/400 >>>file using an Access database. Unfortunately I cannot remember which PC >>>it >>>was on or who the client was. I therefore need to develop a program to >>>search all the modules and class modules in each of the databases on each >>>computer - which would be VERY tedious. >>>As a (more interesting) alternative, does anyone know if the mechanism >>>which >>>displays the list of objects in the selected database when importing >>>database objects is useable independently? If it is, then I can use a >>>recursive directory search (cribbed from the VBScript help manual) to >>>provide the file names, check the HasModule property of each form and >>>search >>>for an appropriate string. >> >> >> A messy problem, but not out of bounds. Once you get a loop >> to find all the mdb files, you can use OpenDatabase to get >> access to its objects. >> >> While modules are objects, you said you want to find >> something inside the code modules. To do that you need to >> use the methods of the module object. Here's some vague air >> code to show the general idea: >> >> >> Dim dbs As DAO.Database >> Dim doc As DAO.Document >> Dim lngLineNo As Long >> Set dbs = OpenDatabase(strPath) >> For Each doc In dbs.Containers("Modules").Documents >> DoCmd.OpenModule doc.Name >> lngLineNo =1 >> If doc.Find("string you are looking for", lngLineNo.1, _ >> doc.CountOfLines, 1000) Then >> Debug.Print Path, doc.Name, lngLineNo >> End If >> DoCmd.Close acModule, doc.Name, acSaveNo >> Next doc >> dbs.Close : Set dbs = Nothing
|
|
|