473,666 Members | 2,114 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 1633
On Thu, 2 Oct 2003 07:02:57 +0200 in comp.databases. ms-access, "marc"
<ad******@clu b-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
1712
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 display a link on the page. This link, when clicked will then restore the modified tags back to their original values.
4
2189
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 as soon as the user types the third digit - the fourth digit would then follow the dash. I've seen this done on several sites now. I know it can be done once the user leaves the textbox with a postback, but I would like to try to accomplish it...
4
1968
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 this, map.GetRoute('Redmond, Washington, United States','seattle, Washington, United States',VEDistanceUnit.KiloMeter,VERouteType.Shortest);
2
1949
by: sylver | last post by:
Hi, Following the discussion that can be found here: http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/fda122b27c008266/909da813c8527282?lnk=gst&q=+dynamically+add+a+script+source&rnum=1#909da813c8527282 I modified mine and was trying to launch an alert message inside the dynamically added script . My sample codes ================================================
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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 we have to send another system
2
1776
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.