wrong Modules.count ...

T

TNL

Hi,
My Access VBA code access a module as following:
debug.print modules("modImportText").CountOfLines
the modul modImportText exists. But I receive always error:
"access can't find the modul ..."

when use VB 6.0 as following:

dim AccApp As Access.Application
Set AccApp = New Access.Application

AccApp.OpenCurrentDatabase "test.mdb"
With AccApp.Modules
For i = 0 To .Count - 1
debug.print .Item(i).Name
Next i
End With

The database test.mdb had 13 modules (4 standard and 9
classmodule, forms and reports), but the Modules.count
returns always only 6.

Why? Can anybody help me?

Thanks
TNL
Why
..
 
T

TNL

Hi,
thanks,
With your code I can access the standard modules, but the
classe module (as formmodule) I can't not.
How can I do?

Thanks
TNL
 
H

Heiko

Hello TNL
if i remember correct not each Form has to have code, and you have to
loop through Containers(Forms) and check if .HasModule=true ?!
Don't know if this is still implemented in Acc 200X.
Heiko
:)
 
T

TNL

Hello Heiko,
my forms have codemodule.
how can I access my formmodule? I want to modify them (not
manually).
:)
TNL
 
H

Heiko

Hello,
this will be my last response to this thread
You have to set a reference to the VBA Extensibilty

Dim i As Long
Dim AccApp As Access.Application
Set AccApp = New Access.Application
Dim docForm As Access.Form
Dim mdForm As Access.Module
Dim strFormName As String
AccApp.Visible = True
AccApp.OpenCurrentDatabase "test.mdb"
For i = 0 To AccApp.CurrentDb.Containers(1).Documents.Count - 1
strFormName = AccApp.CurrentDb.Containers(1).Documents(i).Name
If strFormName = "HERESTHEFORMWHICHTOMODIFY" Then
AccApp.DoCmd.OpenForm strFormName, acDesign
Set docForm = AccApp.Forms(strFormName)
If docForm.HasModule Then
Set mdForm = docForm.Module
With mdForm
Dim intStart As Integer
intStart = .CountOfDeclarationLines + 2
'This will let a MsgBox appear while opening
.InsertLines intStart, "Private Sub Form_Load()"
intStart = intStart + 1
.InsertLines intStart, vbTab & "Msgbox " &
Chr$(34) & "Hello you should be a Script-Kiddie" & Chr$(34) &
",vbinformation+vbokonly," & Chr$(34) & "What the hell are you using
this for ?" & Chr(34)
intStart = intStart + 1
.InsertLines intStart, "End Sub"
intStart = intStart + 1
.InsertLines intStart, vbNewLine
End With
Set mdForm = Nothing
End If
AccApp.DoCmd.Close acForm, strFormName, acSaveYes
End If
Next i
AccApp.CloseCurrentDatabase
AccApp.Quit
Set AccApp = Nothing

Heiko
:)
 
T

TNL

Hello,
Thanks very much. the code works.
I don't need VBA Extensibilty and I must use Containers
("Forms").

I want to read all codemodules to save in Textfiles, in
order to check in source safe.

Thanks
TNL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top