dbTalk Databases Forums  

Module Collection

comp.databases.ms-access comp.databases.ms-access


Discuss Module Collection in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Darlington
 
Posts: n/a

Default Module Collection - 10-21-2010 , 07:52 PM






I want to include a single new line of code in the Activate event in each
form in my application (180 forms).
Rather than open each manually, I was hoping there might be a way to use the
documents and modules collection to open each class module and edit it using
VBA.
Has anyone tried this?
I'm using Access 2002.

--
Bob Darlington
Brisbane

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Module Collection - 10-21-2010 , 09:11 PM






"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote

Quote:
I want to include a single new line of code in the Activate event in each
form in my application (180 forms).
Rather than open each manually, I was hoping there might be a way to use
the documents and modules collection to open each class module and edit it
using VBA.
Has anyone tried this?
I'm using Access 2002.

--
Bob Darlington
Brisbane
Public Sub TestEventCreate()
Dim item As Variant, i As Long

For Each item In CurrentProject.AllForms
DoCmd.OpenForm item.Name, acDesign
With Forms(0).Module
i = .CreateEventProc("Activate", "Form")
.ReplaceLine i + 1, "'A comment"
End With
DoCmd.Close acForm, item.Name
Next
End Sub

That will open all forms in design view, create an Activate event and insert
a comment in it. Replace the comment to insert the code you need.

This code assumes it's running in a standard module and that there are no
open forms.

Caution - untested air code. Backup first.

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Module Collection - 10-21-2010 , 10:37 PM



Stuart McCall wrote:

Quote:
"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote in message
news:4cc0e029$0$25481$afc38c87 (AT) news (DOT) optusnet.com.au...

I want to include a single new line of code in the Activate event in each
form in my application (180 forms).
Rather than open each manually, I was hoping there might be a way to use
the documents and modules collection to open each class module and edit it
using VBA.
Has anyone tried this?
I'm using Access 2002.

--
Bob Darlington
Brisbane


Public Sub TestEventCreate()
Dim item As Variant, i As Long

For Each item In CurrentProject.AllForms
DoCmd.OpenForm item.Name, acDesign
With Forms(0).Module
i = .CreateEventProc("Activate", "Form")
.ReplaceLine i + 1, "'A comment"
End With
DoCmd.Close acForm, item.Name
Next
End Sub

That will open all forms in design view, create an Activate event and insert
a comment in it. Replace the comment to insert the code you need.

This code assumes it's running in a standard module and that there are no
open forms.

Caution - untested air code. Backup first.


Adding to Stuart's reply, go to Help. Search for "module object". Then
look at the methods; Find, ReplaceLine, InsertLines, InsertText,
CreateEventProc, etc. Most if not all have code examples. You might
want to do this only for form's that currently have an event, perhaps an
event with specific text.

Reply With Quote
  #4  
Old   
Bob Darlington
 
Posts: n/a

Default Re: Module Collection - 10-21-2010 , 11:36 PM



Thanks Stuart.
Just what I wanted.

--
Bob Darlington
Brisbane
"Stuart McCall" <smccall (AT) myunrealbox (DOT) com> wrote

Quote:
"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote in message
news:4cc0e029$0$25481$afc38c87 (AT) news (DOT) optusnet.com.au...
I want to include a single new line of code in the Activate event in each
form in my application (180 forms).
Rather than open each manually, I was hoping there might be a way to use
the documents and modules collection to open each class module and edit
it using VBA.
Has anyone tried this?
I'm using Access 2002.

--
Bob Darlington
Brisbane

Public Sub TestEventCreate()
Dim item As Variant, i As Long

For Each item In CurrentProject.AllForms
DoCmd.OpenForm item.Name, acDesign
With Forms(0).Module
i = .CreateEventProc("Activate", "Form")
.ReplaceLine i + 1, "'A comment"
End With
DoCmd.Close acForm, item.Name
Next
End Sub

That will open all forms in design view, create an Activate event and
insert a comment in it. Replace the comment to insert the code you need.

This code assumes it's running in a standard module and that there are no
open forms.

Caution - untested air code. Backup first.


Reply With Quote
  #5  
Old   
Bob Darlington
 
Posts: n/a

Default Re: Module Collection - 10-21-2010 , 11:37 PM



Thanks Salad.
I had looked in help before posting, but searched on 'modules' instead of
'module', and got very little help.
The 'module' topic seems to have every thing I need.

--
Bob Darlington
Brisbane
"Salad" <salad (AT) oilandvinegar (DOT) com> wrote

Quote:
Stuart McCall wrote:

"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote in message
news:4cc0e029$0$25481$afc38c87 (AT) news (DOT) optusnet.com.au...

I want to include a single new line of code in the Activate event in each
form in my application (180 forms).
Rather than open each manually, I was hoping there might be a way to use
the documents and modules collection to open each class module and edit
it using VBA.
Has anyone tried this?
I'm using Access 2002.

--
Bob Darlington
Brisbane


Public Sub TestEventCreate()
Dim item As Variant, i As Long

For Each item In CurrentProject.AllForms
DoCmd.OpenForm item.Name, acDesign
With Forms(0).Module
i = .CreateEventProc("Activate", "Form")
.ReplaceLine i + 1, "'A comment"
End With
DoCmd.Close acForm, item.Name
Next
End Sub

That will open all forms in design view, create an Activate event and
insert a comment in it. Replace the comment to insert the code you need.

This code assumes it's running in a standard module and that there are no
open forms.

Caution - untested air code. Backup first.


Adding to Stuart's reply, go to Help. Search for "module object". Then
look at the methods; Find, ReplaceLine, InsertLines, InsertText,
CreateEventProc, etc. Most if not all have code examples. You might want
to do this only for form's that currently have an event, perhaps an event
with specific text.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.