• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

VB6 Problems with SetFocus

I checked my version and it is 6.  But I do not have SetFocus as an option on my textbox.  Am I missing a setting?
0
kkbenj
Asked:
kkbenj
  • 3
  • 2
  • 2
  • +1
1 Solution
 
DerZaubererCommented:
Are you using the regular VB6 TextBox control or some other component?
There should be a SetFocus method on the TextBox.

TextBox1.SetFocus

0
 
HooKooDooKuCommented:
A textbox doesn't have a SetFocus "option".  It has a SetFocus "command" that you call.

If you are not seeing "SetFocus" in the auto-complete, try typing it anyway.

Specifically, try creating a new project and place two textboxs and two command buttons on the form.  Then put the following code inside the form and see if it will compile and execute.


Private Sub Command1_Click()
    Text1.SetFocus
End Sub
Private Sub Command2_Click()
    Text2.SetFocus
End Sub
0
 
kkbenjAuthor Commented:
I have forced the SetFocus even though it does not present.  It gives this error:
Compile error:
Method or data member not found
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DerZaubererCommented:
Is the error about 'SetFocus' method or is it because you misspelled textbox name or because your code cannot see the textbox or is in wrong context?

Maybe give some sample code or more details.
0
 
kkbenjAuthor Commented:
The code and I always cut and paste field names to ensure I don't misspell.

When I click the New button, is highlights the .SetFocus and displays the compile error above.
Private Sub btnNext_Click()
  txtParmNm.SetFocus
End Sub

Open in new window

0
 
Martin LissRetired ProgrammerCommented:
txtParmNm is  probably either accidentally or on purpose a control array. Take a look at the Index value in the IDE for the control. If it is not blank then it's a control array and you need to either remove the Index value or do soumetghing like


txtParmNm(0).SetFocus
0
 
kkbenjAuthor Commented:
Yes - that was the problem.  Thanks!
0
 
Martin LissRetired ProgrammerCommented:
You're welcome.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now