Microsoft KB Archive/189400

= BUG: VBComponents Add Method Cannot Add a Form =

Article ID: 189400

Article Last Modified on 5/13/2003

-

APPLIES TO


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

-



This article was previously published under Q189400



SYMPTOMS
When attempting to add a Form to a Visual Basic project through the IDTExtensibility model, you receive the following error:

Runtime error '-2147467259 (800004005)':

System Error &h80004005(-2147467259). Unspecified error



CAUSE
This error can occur if you use the Add method of the VBComponents object and pass vbext_ct_MSForm as the component type.

vbext_ct_MSForm is not a valid component type; it corresponds to Form3 designers, which Visual Basic does not support.



RESOLUTION
Use the VBComponents AddFromTemplate method. See the MORE INFORMATION Section of this article for additional information.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Problem
 Start a New Add-In Project in Visual Basic. A form "frmAddIn" will be created automatically, with two command buttons, OK and Cancel.  Add the following line to the Click event of the OKButton: VBInstance.VBProjects(1).VBComponents.Add (vbext_ct_MSForm)

 If using Visual Basic 5.0, type "ADDTOINI" in the Immediate (debug) window and press the ENTER key. This step is not necessary if you are using Visual Basic 6.0. Press the F5 key to run the project. Start another instance of Visual Basic with a new standard EXE project.</li> Under the Add-Ins menu, select Add-In Manager, and then select "My AddIn" from the list.</li> Select the "My AddIn" item from the Add-Ins menu.</li> Click OK on the Add-In Form. You will get the error:

Run-time error '-2147467259 (800004005)':

System Error &h80004005(-2147467259). Unspecified error.

</li></ol>

Steps To Work Around the Problem
<ol> Add a new form to the add-in project and save it in the Template folder under the Visual Basic folder as Form1.frm. (For example, C:\Program Files\DevStudio\VB\Template), and then remove the form from the project.</li>  Change the code in the OKButton_Click event in step 2 above to the following code shown below. Private Sub OKButton_Click VBInstance.VBProjects(1).VBComponents.AddFromTemplate _ ("C:\Program Files\DevStudio\VB\Template\Form1.frm") End Sub

NOTE: Modify the path as appropriate for your environment. In Visual Basic 5.0, the default Visual Basic installation path is C:\Program Files\DevStudio\VB. In Visual Basic 6.0, the default path is C:\Program Files\Microsoft Visual Studio\VB98. </li> Repeat steps 3 through 8 in the "Steps to Reproduce the Problem" section. This time a form should be added to your project each time you click OK.</li></ol>

<div class="references_section">