I have a .bas file saved locally that I load into my Acces project to run a particular sub. I use the following code to load the module (which works fine):
For Each Comp In Application.VBE .ActiveVBProjec t.VBComponents
If Comp.Name = ProductName Then
Application.VBE .ActiveVBProjec t.VBComponents. Remove Comp
Exit For
End If
Next
The above works fine (both adding the module and subsequantly removing it) provided I do not run any code within the module once it is loaded. The second I use code within the module the deletion loop does not seem to remove the module immediately (as it would do prior to running any code in the module).
The procedure in it's entirity is as follows:
Public Property Let Product(Product Name As String)
Dim Comp As Object
'Close rates connection if it is already open
If RatesConn.State <> 0 Then RatesConn.Close
'Remove old code modules
For Each Comp In Application.VBE .ActiveVBProjec t.VBComponents
If Comp.Name = ProductName Then
Application.VBE .ActiveVBProjec t.VBComponents. Remove Comp
Exit For
End If
Next
Really baffling, if no code is run within the loaded BAS the deletion loop removes the module immediately and a fresh version of the ub can be loaded. If code is run the deletion loop does not work immediately and when the procedure comes to add a fresh version of the BAS it creates a duplicate with "1" on the end.
I have tried substituting the deletion loop with a simple docmd.deletobje ct acmodule, ProductName without much luck.
Are you only able to add/remove modules whilst no code within that module has been run?
Any help greatly appreciated!!
Thanks
EDIT: Just to point out the obvious, I have made sure that all code within the loaded bas has finished executing prior to attempting to remove it.
I've experimented a while with this problem and the only way I could reproduce the bug is when subroutine supposed to remove module contain early compiled call to public subroutine in the module to delete.
e.g.
Module: Module1
Expand|Select|Wrap|Line Numbers
Public Sub Sub1()
.....
End Sub
Module: Main
Expand|Select|Wrap|Line Numbers
Public Sub DelAndImport()
With Application.VBE.ActiveVBProject.VBComponents
.Remove .Item("Module1")
.Import "X:\Module1.bas"
Sub1
End With
End Sub
on the other hand, indirect call of the sub works flawlessly
Module: Module1
Expand|Select|Wrap|Line Numbers
Public Sub Sub1()
.....
End Sub
Module: Main
Expand|Select|Wrap|Line Numbers
Public Sub DelAndImport()
With Application.VBE.ActiveVBProject.VBComponents
.Remove .Item("Module1")
.Import "X:\Module1.bas"
Run "Sub1"
End With
End Sub
This, I guess, makes a perfect sense. Since there is a compiled and running code referencing code module, it could not be removed.
So, in few words, the problem is not that the module is loaded since some code in it has been invoked, but that there is a compiled call to this module in code being executed.
Don't forget 2 other viable, and probably more efficient approaches to running Functions/Sub-Routines in External Modules, namely:
Create a Library Database (*.mda/*.mde) consisting of the Module's functionality. You could then set a Reference, either manually or dynamically, to this Library Database and access its Sub-Routines, Functions, Constants, etc...
(Automation) - Set an Object Reference to the Database containing the External Module, then use the Run Method of the Application Object to execute its Routines, etc. This approach, would of course, involve encapsulating the Module's Code within a DB.
I feel as though either approach would be better than the current one.
I have managed to delete a BAS then import a new version and then run the sub within the loaded BAS without any trouble. The problem arrives when I try to remove this BAS to load a new one.
The database is a motor insurance quote engine which will need to load one of several hundred BAS files at runtime dependant on the effective month / years rates selected by the user. I have attached a number of screenshots to try to better highlight this. It seems the first time a BAS is removed and a new one loaded everything works fine, however, each subsequant BAS seems to cease any classes that are active (they will appear to be set back to Nothing).
We are limited on space hence why we are not using multiple MDB files to act as code containers.
EDIT: Have uploaded a ZIP with the full size screenshots.
@FishVal
I've not tried to indirectly call, will give that a go now.
The code generates an insurance premium. Although the same table of risk information is used to generate a premium i.e. they all use Driver's Sex, Age, Vehicle, Cover etc they behave differently when generating underwriting terms based on this information (be it differing excesses, endorsements, premium breakdowns). Some of the product BAS files require little over 200 lines of code to achieve the final premium, others are closer to 2000.
@Nates
Any possibility of Uploading a Mini-Version of your DB with only a few Modules, and only the minimal and essential code that is failing? You need only to include the relevant code along with any other specifics. The data itself is also irrelevant, can even be dummy, and need only parallel the actual data in the DB.
Dear friends,
I am having a hard time understanding how to use a SELECT CASE in ASP. I
have used it in VB but never in ASP scripting.
Scenerio:
I have 2 textboxes on a form that I have to allow entry to one or the other
or Both at the same time. Now I tried to use an If ElseIf but it got too
hard to track, so now I am using a SELECT CASE Statement.
This is a request for help fixing a SQL Server 2000/ADO problem on Windows
XP. I would appreciate any useful assistance.
PROBLEM: SQL Server access on my machine fails as follows:
1. All of my VB6 apps reference the following ADO typelib:
Microsoft ActiveX Data Objects 2.7 Library
Located at:
c:\Program Files\Common Files\System\ADO\msado27.tlb
I have a problem that I am trying to solve. We have a huge product with a
whole lot of ASP and VB code. VB code is all ActiveX dlls which are used by
ASP app. When I attempt to add features or fix bugs, I like to execute the
dlls in debug so I can see what is going on. (Some folks in my org seem to
have this kinda wacky bias against debugging, as if *real* programmers
should not need a debugger. Whatever, it is the fastest way for me to get...
I have a problem I cannot solve.
My application hosts IE activex control. I follow the standard procedure: I
just aximp shdocvw.dll. Note that this gives you two files: axshdocvw.dll
and shdocvw.dll.
And there comes the problem. I reference the libraries from my project. For
this to work, I put the libraries in the same directory as the application.
Now, from my code I try to ShellExecute to a link (to show it in a new
window):
Hi
When I'm debugging and somewhere in the code I have a breakpoint, many
times when the code after breakpoint finishes and the app returns I
can do nothing within in it(it's like freeze)... The app behaves
strangely and not accepts any event even close event!!!!! It just
lefts for me to stop debugging clicking the respective button in the
vs.net toolbar... I don't know if this behaviour is a bug of vs.net or
if it's consequence of bad...
Gentlemen: I am having one heck of a time taking a DAO walk through
the records in an SQL dynaset. I'm trying to walk a set of records
returned by a UNION query. I'm attempting to filter the records to
those related to vehicle #60 ( = 60 ). If I explicitly
specify 60 in the SQL ==everything works fine. Take a look:
100 PString = "SELECT & " & Chr$(&H22) & Space(1) &
Chr$(&H22) & " & AS Recipient "
120 PString = PString & "FROM...
I am trying to write a script that deletes certain files based on
certain criteria.
What I am trying to do is to automate the process of deleting certain
malware files that disguise themselves as system files and hidden
files. When I use os.remove() after importing the os module is raises
a Windows Error: Access denied probably because the files have
disguised themselves as system files. Is there anway to get adequate
privileges under...
I have this nasty problem with Shared methods and what I think of as "global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is ButtonHasBeenClicked.
In this simple example code in Form1 calls a routine in Module1 which then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenClicked but the reference to ButtonHasBeenClicked...
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...
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,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
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...
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();...
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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