ACC2000: Access Automation Causes Run-Time Error -2147467259 (209157)
The information in this article applies to:
This article was previously published under Q209157 For a Microsoft Access 2002 version of this article, see 286126.
SYMPTOMS
While opening Microsoft Access and a form through Automation and setting focus to the the form custom menu bar, the following Microsoft Visual Basic error message occurs:
Run-time error '-2147467259 (80004005)':
Method 'SetFocus' of object 'CommandBarPopup' failed
CAUSESetFocus fails because the control, in this case the menu bar, is not visible in the user interface at the time the Automation code executes.
RESOLUTIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this behavior, use either of the following methods:
Method 1: Trap for the Error
Enter a function similar to the following:
Function AutomationTest()
On Error GoTo AutomationErr
<Automation code goes here>
AutomationExit:
Exit Function
AutomationErr:
If Err.Number = -2147467259 Then
Resume 'until control is visible.
Else
<handle any other errors>
End If
End Function
Method 2: Insert a Time Delay
Set focus using code behind the form instead of the Automation code. For example, set the form TimerInterval to 1000 (the value assigned may vary). Then add the following code to the form:
Private Sub Form_Timer()
Me.TimerInterval = 0
Application.CommandBars.ActiveMenuBar.Controls(1).SetFocus
End Sub
REFERENCESFor more information about Automation, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type understanding Automation in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbprb KB209157 |
---|
|