473,508 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modify source script dynamically ?

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
2 1622
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
An if-then-else block or a select case true block?
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1699
by: Got2Go | last post by:
Hello, I am trying to come up with a function that will search the source of the page for a specific string. If that string is found, then have it modify specific tags inside of a table and...
4
2185
by: Jason Cowsill | last post by:
Hi - I am looking for a way to dynamically alter a textbox WHILE the user is typing in it. One example would be while a user is entering their phone number a dash would be entered automatically...
4
1960
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
2
1938
by: sylver | last post by:
Hi, Following the discussion that can be found here:...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.