Microsoft KB Archive/258233

= PRB: Potential Problem with Reloading a UserControl File with an Add-In =

Article ID: 258233

Article Last Modified on 7/10/2001

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q258233



SYMPTOMS
You have a Visual Basic add-in component that calls the VBComponent.Reload method of the Visual Basic Add-In model to reload a UserControl (.ctl) file. If an instance of the UserControl is currently sited on a container (form or control) that is part of the project, you get the following error message when the Reload method is called:

Run-time error '5':Invalid procedure call or argument.



CAUSE
This behavior is by design. The Reload method needs to unload (remove) and then load (add) the .ctl file. Because an instance of the control is on a container, the removal of the control from the project is not allowed. This is analogous to the situation in which you site a UserControl on a form, and then try to remove the .ctl file manually, in which case you get the following error message:

Can't remove control or reference; in use.



Steps to Reproduce the Behavior
 Create a Visual Basic 6.0 Add-In project with a default form (frmAddIn) and a default designer (Connect).  Replace the code in the OKButton_Click event handler on frmAddIn with the following: VBInstance.ActiveVBProject.VBComponents.Item("usercontrol1").Reload MsgBox "UserControl has been reloaded."  Compile the add-in project (MyAddIn.dll). Create a new standard EXE project. Form1 is created automatically. Add a UserControl (UserControl1) to the project and save the project. On the Add-Ins menu, select Add-In Manager.... Select My Add-In, and check the Loaded/Unloaded check box under Load Behavior on the Add-In Manager dialog box. Click OK.</li> On the Add-Ins menu, select My Add-in, and the dialog box (frmAddin) of the MyAddIn project appears.</li> Click OK, and note that a message box appears indicating that the control has been reloaded.</li> Add an instance of the control to Form1 and click OK on the dialog box again. Note that the following error message appears:

Run-time error '5': Invalid procedure call or argument.

</li></ol>

Additional query words: MyAddIn 5 can t run time

Keywords: kbaddin kbprb KB258233

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.