Editing modules dynamically

G

Guest

Hi all

I’m trying to dynamically modify a module. The idea is start with just a
blank function in the module. The code that I’m trying to write will place
code into the function, execute it, and then remove the lines again, leaving
just the blank function again.

The code to place code in the function, and then delete it when it’s been
run is working fine. The problem is that when I close the database, I get
prompted to save changes to the module. I don’t want this.

I have found that if I use DoCmd.Close to explicitly close the module after
the code runs [in order that I can prevent the Save prompt], the module is
removed from the modules collection and I can’t access it. If I counteract
this by opening it using DoCmd.Open, it opens visibly.

So, is there a way I can open the module where I can edit it dynamically but
leaving it invisible?

Or alternatively is there a way I can specify that I don’t want to save
changes to the module without having to explicitly close it?

Many thanks

David
 
D

David C. Holley

WHY? I have never heard of a situtation where code needs to be created
dynamically to begin with. I dare say that pretty much every language
that's been created has enough program-flow statements (eg.
IF...THEN...ELSE, SELECT CASE, FOR...NEXT) to do anything that a module
created dynamically could do. PLUS if you're creating the code
on-the-fly there's a higher probablity of introducing flat-out syntax
errors or error-free bugs (eg miscalulcations, etc.)

Its one thing to create modules via code (that's how the wizards work),
but another to try it with run-time code.

What exactly are you trying to accomplish? What are the modules created
dynamically supposed to do?

David H
 
G

Guest

Hi David

Thanks for your reply. I want to create a situation where I can execute a
string as code. As far as I am aware, no function in Visual Basic exists to
do this. However, you can put the string into a module function and execute
it that way.

Do you have any suggestions how I might accomplish this?

Thanks again

David

David C. Holley said:
WHY? I have never heard of a situtation where code needs to be created
dynamically to begin with. I dare say that pretty much every language
that's been created has enough program-flow statements (eg.
IF...THEN...ELSE, SELECT CASE, FOR...NEXT) to do anything that a module
created dynamically could do. PLUS if you're creating the code
on-the-fly there's a higher probablity of introducing flat-out syntax
errors or error-free bugs (eg miscalulcations, etc.)

Its one thing to create modules via code (that's how the wizards work),
but another to try it with run-time code.

What exactly are you trying to accomplish? What are the modules created
dynamically supposed to do?

David H

David said:
Hi all

I’m trying to dynamically modify a module. The idea is start with just a
blank function in the module. The code that I’m trying to write will place
code into the function, execute it, and then remove the lines again, leaving
just the blank function again.

The code to place code in the function, and then delete it when it’s been
run is working fine. The problem is that when I close the database, I get
prompted to save changes to the module. I don’t want this.

I have found that if I use DoCmd.Close to explicitly close the module after
the code runs [in order that I can prevent the Save prompt], the module is
removed from the modules collection and I can’t access it. If I counteract
this by opening it using DoCmd.Open, it opens visibly.

So, is there a way I can open the module where I can edit it dynamically but
leaving it invisible?

Or alternatively is there a way I can specify that I don’t want to save
changes to the module without having to explicitly close it?

Many thanks

David
 
D

David C. Holley

Can you post a sample of the string that you want to execute? Also,
where is the string coming from?

David said:
Hi David

Thanks for your reply. I want to create a situation where I can execute a
string as code. As far as I am aware, no function in Visual Basic exists to
do this. However, you can put the string into a module function and execute
it that way.

Do you have any suggestions how I might accomplish this?

Thanks again

David

:

WHY? I have never heard of a situtation where code needs to be created
dynamically to begin with. I dare say that pretty much every language
that's been created has enough program-flow statements (eg.
IF...THEN...ELSE, SELECT CASE, FOR...NEXT) to do anything that a module
created dynamically could do. PLUS if you're creating the code
on-the-fly there's a higher probablity of introducing flat-out syntax
errors or error-free bugs (eg miscalulcations, etc.)

Its one thing to create modules via code (that's how the wizards work),
but another to try it with run-time code.

What exactly are you trying to accomplish? What are the modules created
dynamically supposed to do?

David H

David said:
Hi all

I’m trying to dynamically modify a module. The idea is start with just a
blank function in the module. The code that I’m trying to write will place
code into the function, execute it, and then remove the lines again, leaving
just the blank function again.

The code to place code in the function, and then delete it when it’s been
run is working fine. The problem is that when I close the database, I get
prompted to save changes to the module. I don’t want this.

I have found that if I use DoCmd.Close to explicitly close the module after
the code runs [in order that I can prevent the Save prompt], the module is
removed from the modules collection and I can’t access it. If I counteract
this by opening it using DoCmd.Open, it opens visibly.

So, is there a way I can open the module where I can edit it dynamically but
leaving it invisible?

Or alternatively is there a way I can specify that I don’t want to save
changes to the module without having to explicitly close it?

Many thanks

David
 
G

Guest

The idea is to pass the string contained within the OpenArgs argument of
DoCmd.OpenForm, which will set defaults and formatting for a dialog form.
This form can be opened from a wide range of locations, but may need
different properties and default values from each one.

As such, there is no one string that I want to execute.



David C. Holley said:
Can you post a sample of the string that you want to execute? Also,
where is the string coming from?

David said:
Hi David

Thanks for your reply. I want to create a situation where I can execute a
string as code. As far as I am aware, no function in Visual Basic exists to
do this. However, you can put the string into a module function and execute
it that way.

Do you have any suggestions how I might accomplish this?

Thanks again

David

:

WHY? I have never heard of a situtation where code needs to be created
dynamically to begin with. I dare say that pretty much every language
that's been created has enough program-flow statements (eg.
IF...THEN...ELSE, SELECT CASE, FOR...NEXT) to do anything that a module
created dynamically could do. PLUS if you're creating the code
on-the-fly there's a higher probablity of introducing flat-out syntax
errors or error-free bugs (eg miscalulcations, etc.)

Its one thing to create modules via code (that's how the wizards work),
but another to try it with run-time code.

What exactly are you trying to accomplish? What are the modules created
dynamically supposed to do?

David H

David Cleave wrote:

Hi all

I’m trying to dynamically modify a module. The idea is start with just a
blank function in the module. The code that I’m trying to write will place
code into the function, execute it, and then remove the lines again, leaving
just the blank function again.

The code to place code in the function, and then delete it when it’s been
run is working fine. The problem is that when I close the database, I get
prompted to save changes to the module. I don’t want this.

I have found that if I use DoCmd.Close to explicitly close the module after
the code runs [in order that I can prevent the Save prompt], the module is
removed from the modules collection and I can’t access it. If I counteract
this by opening it using DoCmd.Open, it opens visibly.

So, is there a way I can open the module where I can edit it dynamically but
leaving it invisible?

Or alternatively is there a way I can specify that I don’t want to save
changes to the module without having to explicitly close it?

Many thanks

David
 
K

Kevin K. Sullivan

Wow, sounds like you are openning yourself for a mess of corruption.
Just editting modules while in break mode can cause trouble -- I'd
suggest reviewing your back-up plan before proceeding.

I would suggest that you change paths from editting modules to editting
external text files. You'll have complete control of the modules that
way. You could then:

create text file "Full.bas" with Open #, Print #, etc.
export the old module "modDynaCode" as "Empty.bas"
delete the module
import "Full.bas" as the new module "modDynaCode"
run the code
delete the module "modDynaCode"
import "Empty.bas" as the module "modDynacode"

Check out DoCmd.Echo False to prevent the display of your UI changes.
Just be sure that your error handling code sets DoCmd.Echo True, or the
application will appear to be frozen.

Of course, I haven't done this, so I don't know the pitfalls of this
path, but I think it would break the process into safer, discrete steps.

Good luck and tell the group how it works out!

HTH,

Kevin
 
D

David C. Holley

Can you post a sample of the STRING that you're going to pass to the
OpenArgs?

David said:
The idea is to pass the string contained within the OpenArgs argument of
DoCmd.OpenForm, which will set defaults and formatting for a dialog form.
This form can be opened from a wide range of locations, but may need
different properties and default values from each one.

As such, there is no one string that I want to execute.



:

Can you post a sample of the string that you want to execute? Also,
where is the string coming from?

David said:
Hi David

Thanks for your reply. I want to create a situation where I can execute a
string as code. As far as I am aware, no function in Visual Basic exists to
do this. However, you can put the string into a module function and execute
it that way.

Do you have any suggestions how I might accomplish this?

Thanks again

David

:



WHY? I have never heard of a situtation where code needs to be created
dynamically to begin with. I dare say that pretty much every language
that's been created has enough program-flow statements (eg.
IF...THEN...ELSE, SELECT CASE, FOR...NEXT) to do anything that a module
created dynamically could do. PLUS if you're creating the code
on-the-fly there's a higher probablity of introducing flat-out syntax
errors or error-free bugs (eg miscalulcations, etc.)

Its one thing to create modules via code (that's how the wizards work),
but another to try it with run-time code.

What exactly are you trying to accomplish? What are the modules created
dynamically supposed to do?

David H

David Cleave wrote:


Hi all

I’m trying to dynamically modify a module. The idea is start with just a
blank function in the module. The code that I’m trying to write will place
code into the function, execute it, and then remove the lines again, leaving
just the blank function again.

The code to place code in the function, and then delete it when it’s been
run is working fine. The problem is that when I close the database, I get
prompted to save changes to the module. I don’t want this.

I have found that if I use DoCmd.Close to explicitly close the module after
the code runs [in order that I can prevent the Save prompt], the module is
removed from the modules collection and I can’t access it. If I counteract
this by opening it using DoCmd.Open, it opens visibly.

So, is there a way I can open the module where I can edit it dynamically but
leaving it invisible?

Or alternatively is there a way I can specify that I don’t want to save
changes to the module without having to explicitly close it?

Many thanks

David
 

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