DOC: FindControl Recursive Argument Not Used with CommandBars Collection (279676)



The information in this article applies to:

  • Microsoft Office 97 Developer Edition
  • Microsoft Office 2000 Developer

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:

<CommandBars object>.FindControl(Type, Id, Tag, Visible)


Steps to Reproduce the Problem

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. In the Project References dialog, select Microsoft Office Object Library and Microsoft Outlook Object Library.
  3. 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("outlook.application")
    Set colCmdBars = olAPP.ActiveExplorer.CommandBars
    
    'Fails with compile error.
    Set oCmdBarCtrl = colCmdBars.FindControl(Type:=msoControlButton, Recursive:=True)
    
    MsgBox oCmdBarCtrl.Id
    					
  4. If Outlook is not already running, start Outlook and then return to the Visual Basic project.
  5. Press F5 to run the program. Click the button. A compile error occurs on the line that calls the FindControl method.
  6. Remove the Recursive argument and repeat the previous step. No error occurs.

REFERENCES

Help Topics for CommandBars object, CommandBar object, FindControl method.

173604 OL97: How to Use Command Bars in Outlook Solutions


Modification Type:MajorLast Reviewed:12/15/2003
Keywords:kbbug kbdocerr kbfix KB279676