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

Set Focus issues

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am having a set focus issue and I can't seem to get around it. I have a text box (txtFindFile) and a command button (cmdBrowse). When the user clicks on the button, the common dialog box pops up and after the user selects what file he/she is looking for, it stores this filename in a string variable called FilePath. After the file path is selected, I want this path to appear in the text box. Here my code for clicking the button. findfile is my common dialog control.

Private Sub cmdBrose_Click()
findfile.InitDir = "C:\Windows\Desktop\MyFolder"
findfile.ShowOpen 'Open the dialog box
FilePath = findfile.FileName 'Store the path
txtFindFile.SetFocus
txtFindFile.Text = FilePath
End Sub

Everything works fine except when I try to set the focus of txtFindFile. If I leave that line out, I get the error that I can't access the text box unless it has the focus. I have tried creating a function that would move the focus, but that doesn't work. I have also tried to find something where the form would move the focus to the next tabindex, but I can't come up with anything. Any ideas would be appreciated. Thanks!!!
 
Don't fully qualify the text box. Instead of this:

txtFindFile.Text = FilePath

Just do this:

me.txtFindFile = FilePath

The .text property of the text box is the default property.
 
Hi!

Databaseguy is correct, but there is a couple of other things you probably ought to know. First, you can access the value property of the text box without setting the focus to the textbox and that will allow the information to appear in the textbox. Second, to use the SetFocus method you need the keyword Call. So your line should read:

Call txtFindFile.SetFocus

Then you could use the .text property if you wanted to.

hth
Jeff Bridgham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top