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!!!
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!!!