Cannot Understand Containers, Forms, Documents and Modules

  • Thread starter Thread starter chammock
  • Start date Start date
C

chammock

I must be missing something with the terminology. I have a tool that
iterates through a form's controls and deletes them if they are command
buttons. Unfortunately, deleting a command button does not delete the
code that goes with them, such as click events like,

Private Sub vbacmdA1_Click()
MsgBox "Way cool!"

End Sub

I need to delete the click events and I know the form and the name of
the click event, since I created them programmatically. When I am
trying to iterate through click events, I consider those modules. But
when I try something like

For I = Modules.Count - 1 To 0 Step -1

to step through the click events, I end up getting the name of the
forms in my database back.

I have tried using Set cnt = db.Containers("Modules") and

For I = cnt.Documents.Count - 1 To 0 Step -1

to get to the code and it does something but not what I want.

I have tried using Documents.count , thinking that these may represent
the click event code, but cannot get there either.

So if anyone has the key to get to what I call code behind, please pass
it on. Thanks.
 
I need to delete the click events and I know the form and the name of
the click event, since I created them programmatically. When I am
trying to iterate through click events, I consider those modules. But
when I try something like

For I = Modules.Count - 1 To 0 Step -1

to step through the click events, I end up getting the name of the
forms in my database back.

The problem is that each Form has *ONE* Module - which may have many
Subs in it. Each subroutine within the module is just part of the text
of the entire module, and has no independent existance.

John W. Vinson[MVP]
 
So would I have to parse through the ONE Module for a Form and Identify
each line and use DeleteLines method? Also, I am using a frmTest with a
command button to test out deletion of the Sub. When I try (as a test)

If frm.Properties("HasModule") Then
Set mdl = frm.Module
MsgBox (mdl.CountOfLines)

it always returns the number of lines of the module for frmTest, not
frmPanelRightTemplate.

I have tried to Set frm = frmPanelRightTemplate and other things but it
always returns the lines of code for frmTest.

Thanks for any additional help you can provide.
 
DoCmd.OpenForm "frmPanelRightTemplate", acDesign, , , ,acHidden
Set frm = Forms("frmPanelRightTemplate")

' do your stuff

DoCmd.Close acForm, "frmPanelRightTemplate", acSaveNo


The reason for this is that the Forms collection only contains those forms
that are open.
 
Doug, thanks so much. That got me to the correct form. Now I need to
figure out how to parse through the code in the form module to delete
those Click Events that I am creating programatically. I will do a
little more research on that.
 
I have made so much progress with the help of people on this board.
Thanks.

Now I need to tie it all together. I have a test button to cleanup a
form by deleting a bunch of controls and the click events associated
with them. It works fine. Now I am trying to have the Cleanup routine
run when the form closes. I need to switch the form into design view,
from the normal view, to delete these items and it seems to have a
problem switching over to Design view in the On Close event. Any ideas?
 
Back
Top