Cannot set focus on a textbox

DBROWN

Registered User.
Local time
Today, 07:21
Joined
Mar 22, 2012
Messages
10
Hello, I hope someone might be able to help me out here. I have a form I have designed to rename a pdf file while viewing it. I placed a webbrowser control on the form for viewing. When the user clicks the "rename" button I navigate away from the current pdf file to prevent "file access errors". What I am trying to do is move the focus back the the textbox used for renaming after the code finishes to keep the user from having to click in the field every time. I have included the code below and thank you very much in advance!

Private Sub cmdRename_Click()
On Error GoTo Err_cmdRename_Click
Dim WBrowser As WebBrowser, strPath As String, strNew As String, strNAV As String
With Me
strPath = .txtFolder & "\" & .lstFiles
strNew = .txtFolder & "\" & .NewName & ".pdf"
strNAV = .txtFolder
Set WBrowser = .AcroPDF0.Object
End With
With WBrowser
.Navigate2 (strNAV)
End With
Call Wait
With Me
If Len(.NewName) > 1 Then
Name strPath As strNew
.lstFiles.RemoveItem (.lstFiles)
.lstFiles.Value = .lstFiles.ItemData(0)
End If
End With
With Me
strPath = .txtFolder & "\" & .lstFiles
End With
With WBrowser
.Navigate2 (strPath)
End With
DoEvents
Set WBrowser = Nothing
With Me
.NewName.SetFocus
.NewName.SelStart = 0
.NewName.SelLength = Len(.NewName)

End With
Exit_cmdRename_Click:
Exit Sub

Err_cmdRename_Click:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_cmdRename_Click

End Sub
 
Set the Focus to the Form before setting focus to the Control.
 
Thanks Rain, I tryed that but it still doesn't work.

With Me
.Form.SetFocus
.NewName.SetFocus
.NewName.SelStart = 0
.NewName.SelLength = Len(.NewName)

End With
 
Thanks again Rain. The link you posted says that if you are on the main form that "Me" is what to use. I don't have any subforms to worry about. I did try "forms!form name" and several other combinations but none worked. I have never had this kind of trouble setting focus on a text box.
 
I believe that you have moved Focus to the Browser, so that is why I am saying to move Focus back to the Form then move to the control.

If I am wrong, then no harn is been done by going to Form then control.

Have you steped through your code to see if all is been executed.

Place some Message Boxes throughout the code to make double sure.
 
Yes, everything is executing. And I did try going to form then control but it didn't make any difference. I even put a message box in at the end to see what is going on.

MsgBox me.ActiveControl.Name

It says that the text box I want to set focus to is the active control. I have also suspected the webbrowser is stealing the focus and Access doesn't realize it.
 
I am at a loss and therefore can only help by making suggestions rather than solutions.

After setting Focus to the Control, do something different. Like change the BackColour.
 
Thanks Rain, I do appreciate your time. I will have to try this in the morning because I have to leave work now. I'll post results in the morning.
 
It is Morning here. 7:30 AM Friday.

Catch you later.
 

Users who are viewing this thread

Back
Top Bottom