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.