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