Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't set focus to a text box !!!!

Status
Not open for further replies.

GAORR

Programmer
Nov 22, 2001
48
CA
I just can't figure it out. I load a form with a number of fields to be entered. I am attempting to 'set focus' to the first text box I want the user to enter data into by:

txtCustLastName.setFocus

I get the following error: error 5 - 'Invalid procedure call or arguement'

I know I could solve this by using the tabindex, but why doesn't it work??

Thanks for any help.

 
Set its tabindex property to 0 and all the subequent ones 1,2,3,etc in the order that you would like the user to be able to tab through the form.
 
It probably doesn't work because the form is not yet visible. Try the setfocus statement after the form is visible.

Hope this does it.
 
You can only move the focus to a visible form or control. Because the form and controls on the form aren't visible yet until the form's Load event has finished, you can't use the SetFocus method unless you first use the Show method to show the form before the Form_Load event is finished.

Private sub form_load()
form1.show
txtCustLastName.setFocus
end sub

Should work ...
 
hey!

i think you should put this code:
'txtCustLastName.setFocus' under the Form_Activate

Private Sub Form_Activate()
txtCustLastName.setFocus
End Sub

hope this helps...

-takishi
 
Thanks to all for your suggestions !!

Exactly as many said, the form was not yet visible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top