|
-
Jan 30th, 2008, 11:26 AM
#1
Thread Starter
Member
[RESOLVED] why cant we .setfocus on formload?
Private Sub Form_Load()
Me.txt_rno.SetFocus
End Sub
why this fails?
-
Jan 30th, 2008, 11:36 AM
#2
Hyperactive Member
Re: why cant we .setfocus on formload?
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
Last edited by Caskbill; Jan 30th, 2008 at 11:39 AM.
-
Jan 30th, 2008, 12:22 PM
#3
Re: [RESOLVED] why cant we .setfocus on formload?
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
-
Jan 30th, 2008, 01:35 PM
#4
Re: [RESOLVED] why cant we .setfocus on formload?
This will probably work too:
The last line in form load
me.show or me.visible = True
text1.setfocus
-
Jan 30th, 2008, 01:59 PM
#5
Re: [RESOLVED] why cant we .setfocus on formload?
Because of this
 Originally Posted by Hack
In short, all of the code in the Form Load will execute before the form becomes visible.
Me.Visible would never evaulate to True so the statement wouldn't run anyway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|