11 Replies - 61093 Views - Last Post: 20 August 2012 - 04:50 AM Rate Topic: -----

#1 omar.ing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-August 09

textbox setfocus in vb6

Posted 20 August 2009 - 11:54 PM

exuse me for the stupid question but i try to set the focus on a text box in form load in vb6 and error show up

error: Run-time error '5': Invalid procedure call of argument

why is this happening.
Is This A Good Question/Topic? 0
  • +

Replies To: textbox setfocus in vb6

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 12:12 AM

What piece of code did you use?
Was This Post Helpful? 0
  • +
  • -

#3 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 12:16 AM

ok dude if you want to set focus in form_load you need to make sure that the for is loaded. becose form_load event is befor the form is show up you need to do this

Private Sub Form_Load()
	Me.Visible=True
	TextBox1.SetFocus
End Sub



that si becose the text box is not draw yet.

good luck

tell me if that help you
Was This Post Helpful? 1
  • +
  • -

#4 omar.ing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-August 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 02:19 AM

text1.SetFocus
Was This Post Helpful? 0
  • +
  • -

#5 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 02:34 AM

Just this:
Private Sub Command1_Click()
Text1.SetFocus
End Sub


Was This Post Helpful? 0
  • +
  • -

#6 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 03:32 AM

in the form.load event, the form ISNT actually loaded, its loading.

try using NoBrains method, that should work.
Was This Post Helpful? 0
  • +
  • -

#7 MuSSi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 84
  • Joined: 05-June 09

Re: textbox setfocus in vb6

Posted 21 August 2009 - 07:57 AM

Try this:

Private Sub Form_Load()
Timer1.Enabled = True
End Sub



Private Sub Timer1_Timer()
Text1.SetFocus
Timer1.Enabled = False
End Sub



there now all you need is a textbox and a timer, hope that works for you
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Johan*


Reputation:

Re: textbox setfocus in vb6

Posted 22 December 2010 - 02:48 AM

View Postomar.ing, on 20 August 2009 - 10:54 PM, said:

exuse me for the stupid question but i try to set the focus on a text box in form load in vb6 and error show up

error: Run-time error '5': Invalid procedure call of argument

why is this happening.



You can't set focus on an object while in form load event.
Try focus an object in form activate event.

Like below example code:
Private Sub Form_Activate()
txtServer.SetFocus
End Sub

I usually do that and no problem occurs
Was This Post Helpful? 0

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: textbox setfocus in vb6

Posted 26 February 2011 - 01:36 PM

I usually use the Activate Event when I have to do this as well. I do like NoBrain's solution, never thought of that before. If you make the form visible, it will finish loading before it executes the next line of code. Otherwise, it will make itself visible at the end of the Form_Load event.

However, I'm sorry to say that I'm not sure I like ANY of these solutions! :) Suppose we take a step back here and ask why the OP is trying to do this in the first place. It's probably because his TabIndex order is all messed up because he doesn't understand what that's all about.

So Omar, let me ask you to check your tabindex property on each one of your controls. Your textbox's tabindex property should be 0 (well, it should really be 1 and the label next to it should be 0, but that's a discussion for later). You should be able to hit the tab key and run through your controls in the order you want them to be accessed.

Oops, posted on wrong thread. Sorry for necropost.
Was This Post Helpful? 1
  • +
  • -

#10 RePtiR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-August 12

Re: textbox setfocus in vb6

Posted 19 August 2012 - 01:59 PM

Private Sub Form_Load()
Show Me     'OR    Me.Visible = True
Text1.SetFocus
End Sub


Was This Post Helpful? 0
  • +
  • -

#11 rajathetiger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-August 12

Re: textbox setfocus in vb6

Posted 20 August 2012 - 04:27 AM

Hey.... why you write a code.. if can get directly set the property... just select your textbox control and give the tab index value to Zero/(0).

and Done.

And if you required to get the setfocus in code.. then use the Form_Activate event.
Was This Post Helpful? 0
  • +
  • -

#12 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,778
  • Joined: 26-March 09

Re: textbox setfocus in vb6

Posted 20 August 2012 - 04:50 AM

Guys, why you responding to a post that was started 3 years ago?

I'm sure if the OP didn't get a fix to this by now, he would've given up. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1