Private Sub Form_Load()
Me.txt_rno.SetFocus
End Sub
why this fails?
Printable View
Private Sub Form_Load()
Me.txt_rno.SetFocus
End Sub
why this fails?
It fails because the entire form must load before it can be used.
Put your set focus code in the form's Activate Event, not in it's Load Event.
The Activate Event runs immediately after the load event.
Code:Private Sub Form_Activate()
Me.txt_rno.SetFocus
End Sub
In short, all of the code in the Form Load will execute before the form becomes visible.
So, in effect, you are attempting to set focus to a control that is not visible, and that will throw an error.
If you need this control to have the focus when the form opens, then the easiest way, without any code at all, is to set its TabIndex property to 0
This will probably work too:
The last line in form load
me.show or me.visible = True
text1.setfocus
Because of thisMe.Visible would never evaulate to True so the statement wouldn't run anyway.Quote:
Originally Posted by Hack