Microsoft KB Archive/88477

= PRB: SetFocus During Form Load May Cause Illegal Function Call =

Article ID: 88477

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q88477



Symptoms
Using the SetFocus method to set the focus to a specific control on a form during the form load event procedure may result in an &quot;Illegal Function Call&quot; error.

Cause
This error occurs because the form that the control is on is not yet visible.

Resolution
To prevent this error from occurring, execute Form.Show before executing the SetFocus method.



Steps to Reproduce Problem
 Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default. Place a text box (Text1) on Form1.  Add the following code to the Form_Load procedure for Form1: Sub Form_Load Text1.SetFocus End Sub  Press F5 to run the application. The line of code in the load event will be highlighted with the error &quot;Illegal Function Call.&quot;  If you show the form before executing SetFocus, the program will run as expected. Sub Form_Load Form1.Show Text1.SetFocus End Sub 

Additional query words: 2.00 3.00

Keywords: kbprb KB88477

-

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

© Microsoft Corporation. All rights reserved.