Application.VBE .ActiveVBProjec t.VBComponents. Import FileName:=FileP ath & CODE_FOLDER & RatesYear & "\" & RatesMonth & "\" & ProductName & ".bas"I use the following loop to remove the module:
For Each Comp In Application.VBE .ActiveVBProjec t.VBComponentsThe 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).
If Comp.Name = ProductName Then
Application.VBE .ActiveVBProjec t.VBComponents. Remove Comp
Exit For
End If
Next
The procedure in it's entirity is as follows:
Public Property Let Product(Product Name As String)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.
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
'Retrieve most recent code module
Application.VBE .ActiveVBProjec t.VBComponents. Import FileName:=FileP ath & CODE_FOLDER & RatesYear & "\" & RatesMonth & "\" & ProductName & ".bas"
'Establish rates database connection and set product var
RatesConn.Conne ctionString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & FilePath & RATES_FOLDER & RatesYear & "\" & RatesMonth & "\" & ProductName & ".mdb;"
RatesConn.Open
prvProduct = ProductName
End Property
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.