Change Module Names Programatically

I

ingle.kevin

I have an application that just BEGS for the ability to change the
name of a code module at runtime. For instance, let's say I have
parameters for 100 different clients but all need to be handled the
same. I would want to store the parameters and client-specific
procedures in separate modules (Client1, Client2, etc.). The meat-and-
potatoes of the code is in another module (let's call it Module1). The
code within Module1 always calls for the client-specific stuff as
Module2.

So, at runtime, I click a command button on a switchboard, the code
behind the button renames the appropriate client-specific module
(Client1, Client2, etc.) to the generic name I need in the code
(Module2)

Am I asking too much, or is there a way to make this work?

Thanks
 
D

Dave

the 'classic' way of doing that is to make a array of pointers to the
functions and then look up the function to call from the array. its too
early in the morning here to think about how to do that in vba though.
 
J

Jonathan West

I have an application that just BEGS for the ability to change the
name of a code module at runtime. For instance, let's say I have
parameters for 100 different clients but all need to be handled the
same. I would want to store the parameters and client-specific
procedures in separate modules (Client1, Client2, etc.). The meat-and-
potatoes of the code is in another module (let's call it Module1). The
code within Module1 always calls for the client-specific stuff as
Module2.

So, at runtime, I click a command button on a switchboard, the code
behind the button renames the appropriate client-specific module
(Client1, Client2, etc.) to the generic name I need in the code
(Module2)

Am I asking too much, or is there a way to make this work?

OK, there are two ways of handling this.

1. Don't rename the module, but instead use the CallByName function to call
the code in the module you want.

2. Don't put data into code modules, put it somewhere else, and have a
single code module with a routine to which you pass a parameter (presumably
the client name) and get back the data for that client.

I would strongly prefer #2, but given that you may already a long way down
the path to #1, it may suit your purposes sufficiently well.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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