By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,222 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,222 IT Pros & Developers. It's quick & easy.

Modify source script dynamically ?

P: n/a
Hello,

I wish to change a command button's vba script
according to different values (so it is dynamic)

For example :

if A=4 then the script attached to
the command button is "here the first vba script"

if A=61 then the script attached to
the command button is "here the SEcond- vba script"

Is there a way to do that ?
Thank you
M.

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 2 Oct 2003 07:02:57 +0200 in comp.databases.ms-access, "marc"
<ad******@club-internet.fr> wrote:
Hello,

I wish to change a command button's vba script
according to different values (so it is dynamic)

For example :

if A=4 then the script attached to
the command button is "here the first vba script"

if A=61 then the script attached to
the command button is "here the SEcond- vba script"

Is there a way to do that ?


Using object variables of type Module and the lines collection it is
possible, I the same technique to insert error trapping. My TBLib
add-in does this so you can find the code there
(http://easyweb.easynet.co.uk/~trevor...ds/tblib97.zip)

However, you may want to consider the following cons of doing this at
runtime:

1. You might inadvertantly reset your project. Your code may crash.
2. It won't work in an MDE/ADE
3. It requires the module be opened in the GUI, do-able in code but
looks messy.
4. If secured, some users may not have permission to do this.
5. Will set your code into an uncompiled state, may cause a slight
delay in running.

An alternative would be to just call different functions depending the
condition, e.g.

Sub MyCommandButton_Click()
If A = 0 Then
Call MyFunction0
Elseif A = 1 Then
Call MyFunction1
ElseIf A > 1 or A < 0 Then
Call MyFunctionElse
Else
Msgbox "General Error: Reboot Universe"
End If
End Sub

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #2

P: n/a
An if-then-else block or a select case true block?
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.