In the Show event of a form you might be tempted to use SetFocus to select which field the end user should begin working with. However, this method raises an error 5 when applied on a control that is currently invisible.
If the logic of your application should give the focus always to the same control, it is much better to achieve this using the TabIndex property at design time. Conversely, if the form should behave differently according to other conditions, you should use a different approach. I usually prefer to set the focus in the Form_Activate event
Sub Form_Activate() Static done As Boolean If Not done Then done = True Text1.SetFocus End IfEnd Sub
Note that we need a Static variable to discern the first activation of the form
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.






















