Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ripping code from Access 97 with vb 6

Status
Not open for further replies.

nigz

Programmer
Jun 15, 2001
60
GB
Hi - I hacve been trying all day to cycle through all code modules in an access database (using vb6) and then read the individual lines of code out to another file - I come up with loads of problems ..... I can identify the modules but can't open them - any help would be much appreciated. - N
 
Code:
  Dim oApp As Access.Application
  Dim oModule As Access.Module
  Dim nCount As Long
  Dim nLineNumber As Long
  
  Set oApp = New Access.Application
  
  oApp.OpenCurrentDatabase "C:\6479\Fox\Dbf\TimeFile.mdb"
  
  msgbox "read comments here"
  ' open all modules here!
  ' don't have time to figure out how
  ' perhaps you know (and share? I might need it later)
  ' but once all are open then
  ' the code below works
  
  For Each oModule In oApp.Modules
    nCount = oModule.CountOfLines
    For nLineNumber = 1 To nCount
      Debug.Print oModule.Lines(nLineNumber, 1)
    Next nLineNumber
  Next oModule
 
Unfortunatyely my main problem is in opening all or any of the modules - every time I try it falls over, otherwise my code was very similar to your example.
 
>>I can identify the modules but can't open them

How do you identify the modules?
Maybe if you show me how I can help figure out how to open them
 
Code:
Option Explicit

Private Sub Command1_Click()
  Dim oApp ' As Access.Application
  Dim oModule ' As Access.Module
  Dim nCount As Long
  
  Set oApp = CreateObject("Access.Application")
  
  oApp.OpenCurrentDatabase "C:\6479\Fox\Dbf\TimeFile.mdb"
  
  ' if you know the names of all the modules then...
  oApp.DoCmd.OpenModule "MyModule"
  oApp.DoCmd.OpenModule "MyModules2"
  
  For Each oModule In oApp.Modules
    nCount = oModule.CountOfLines
    Debug.Print oModule.Lines(1, nCount)
  Next oModule
  
  oApp.Quit
  Set oApp = Nothing
  
  Print "DONE"
End Sub
 
Have the code modules in the database been protected by a password? This could prevent you from getting to them. Can you view the modules in the Access VBA window?

rgds
Andy
 
OK have just found a much better way of doing things by using the undocumented 'SaveAsText' method -check out
for an example & here is my code fr ripping form code to files....this also includes 'hidden code' generated when visually designing forms.

Private Sub localWriteToText()
On Error GoTo failed

Dim oApp As Access.Application
Dim frm As Access.Form
Dim i As Integer

Set oApp = New Access.Application
cdOpen.Filter = "Access Database|*.mdb"
cdOpen.ShowOpen 'get the access file name

If cdOpen.FileName <> &quot;&quot; Then

'open access data base in readyness to rip code
oApp.OpenCurrentDatabase cdOpen.FileName, False
'rip form code - same can be used for reports, queries, modules etc.
For i = 1 To oApp.Forms.Count
Set frm = oApp.Forms(i - 1)
oApp.SaveAsText acForm, frm.Name, Left(cdOpen.FileName, Len(cdOpen.FileName) - 4) & &quot;_&quot; & frm.Name & &quot;.txt&quot;
Next

End If

exitCode:
Set oApp = Nothing
Exit Sub
failed:
MsgBox Err.Number & &quot; &quot; & Err.Description
Resume exitCode

End Sub

Regards N
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top