V
Vic
I have a form that contains paths and names of word documents that when
clicked it starts word using automation and loads the document. This all
works fine but I would like the focus to stay with word after the document
is opened but focus returns to the access form when the exit sub is
encountered. Can someone please tell me how to force the focus to stay with
word? Here's the code for when a document is clicked:
Private Sub doc_Path_Click()
' Using late binding dim variables as objects
Dim objWord As Object
Dim doc As Object
Dim bolOpenedWord As Boolean
'Get pointer to Word Object
' Handle Error In-Line
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
'If we got an error, that means there was no Word Instance
Set objWord = CreateObject("Word.Application")
'Set Flag to let us know we opened Word
bolOpenedWord = True
End If
'Make Word Instance visible
objWord.Visible = True
'Reset Error Handler
On Error GoTo 0
Set doc = objWord.Documents.Open(Chr(34) & Me.doc_Path & Chr(34))
objWord.Activate
Set doc = Nothing
Set objWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
clicked it starts word using automation and loads the document. This all
works fine but I would like the focus to stay with word after the document
is opened but focus returns to the access form when the exit sub is
encountered. Can someone please tell me how to force the focus to stay with
word? Here's the code for when a document is clicked:
Private Sub doc_Path_Click()
' Using late binding dim variables as objects
Dim objWord As Object
Dim doc As Object
Dim bolOpenedWord As Boolean
'Get pointer to Word Object
' Handle Error In-Line
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
'If we got an error, that means there was no Word Instance
Set objWord = CreateObject("Word.Application")
'Set Flag to let us know we opened Word
bolOpenedWord = True
End If
'Make Word Instance visible
objWord.Visible = True
'Reset Error Handler
On Error GoTo 0
Set doc = objWord.Documents.Open(Chr(34) & Me.doc_Path & Chr(34))
objWord.Activate
Set doc = Nothing
Set objWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub