Microsoft KB Archive/279676

= DOC: FindControl Recursive Argument Not Used with CommandBars Collection =

Article ID: 279676

Article Last Modified on 12/15/2003

-

APPLIES TO


 * Microsoft Office 97 Developer Edition
 * Microsoft Office 2000 Developer Edition

-



This article was previously published under Q279676



SUMMARY
The online Help topic for the FindControl method incorrectly states that the Recursive argument may be used with either a CommandBar object or a CommandBars collection object. However, the Recursive argument can only be used when referring to a single CommandBar object.



MORE INFORMATION
Attempting to specify the Recursive argument when using the FindControl method with a CommandBars collection object generates a compile error:

Named Argument Not Found

-or-

Wrong number of arguments or invalid property assignment.

The correct syntax for the FindControl method when used with a CommandBars collection object is:

.FindControl(Type, Id, Tag, Visible)

Steps to Reproduce the Problem
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. In the Project References dialog, select Microsoft Office Object Library and Microsoft Outlook Object Library.  Add a CommandButton to Form1 and paste the following code to the button Click event: Dim colCmdBars As Office.CommandBars Dim oCmdBar As Office.CommandBar Dim olAPP As Outlook.Application Dim oCmdBarCtrl As Office.CommandBarControl

Set olAPP = CreateObject(&quot;outlook.application&quot;) Set colCmdBars = olAPP.ActiveExplorer.CommandBars

'Fails with compile error. Set oCmdBarCtrl = colCmdBars.FindControl(Type:=msoControlButton, Recursive:=True)

MsgBox oCmdBarCtrl.Id                    If Outlook is not already running, start Outlook and then return to the Visual Basic project. Press F5 to run the program. Click the button. A compile error occurs on the line that calls the FindControl method. Remove the Recursive argument and repeat the previous step. No error occurs.</li></ol>

<div class="references_section">