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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set focus to textbox using variable name 1

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
Hi

How do I set focus to a text box when the name of the textbox is stored in a variable?

Thanks
 
Try this:

Code:
Dim tbName as String

tbName = "SomeTextBoxName"
Evaluate(tbName).Activate

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Here it goes.
___
[tt]
Dim strVarName
strVarName = "Text2"
CallByName(Me, strVarName, VbGet).SetFocus[/tt]
 
Hmmm The one way I can think of is...

Dim ctlControl As Control
For Each ctlControl In Form1
If TypeName(ctlControl) = "TextBox" And _
ctlControl.Name = sMyTextBoxName Then
ctlControl.SetFocus
Exit For
End If
End If
Next


Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
Wow 3 very different answers... I like clFlava's

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
Unfortunately Evaluate isn't a VB6 function....

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Whoops! Apologies.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Yep, the FAQ is misguided (and merely a god example of someone copying something they read on the internet and assuming it was correct). EbExecuteLine is very, very unreliable in compiled programs. However, we've discussued this issue on numerous occassions in this forum, and provided examples of relatively simple alternatives.

And for this specific case it is really, really simple...

Controls(StringContainingControlName).SetFocus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top