M
Max
I am using the following code from within Access 97 to automate a WordXP
document.
When word is opened instead or reading the document and being left to work
on it the focus of the window comes back to access. I have added these lines
at just before the last end with and still get the problem:
.Application.Visible = True
.WindowState = wdWindowStateMaximize
I have checked the code with break points and nothing runs after this sub is
exited.
Thanks,
Max
Private Sub Button28_Click()
Dim DBPath As String, Template As String, DocPath As String
Dim WordPath As String, TemplatePath As String, Msg As String
Dim appWord As Object 'Word.Application
Dim wdWindowStateMaximize As Long
Dim Quotes As String
wdWindowStateMaximize = 1
Quotes = """"
WordPath = GetWordPath()
TemplatePath = GetTemplatePath()
DocPath = GetDocPath()
WordPath = Quotes & WordPath & Quotes
On Error Resume Next
Template = TemplatePath & Me![DocType].Column(2)
'Get an Application object so you can automate Word.
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
' If no instance running, start word
Set appWord = CreateObject("Word.Application")
End If
'Open a document based on the memo template, turn off the automatic spell
check
DoCmd.Hourglass False
With appWord
.Activate
.Application.Visible = True
.Application.ChangeFileOpenDirectory (DocPath)
.Documents.Add Template
.WindowState = wdWindowStateMaximize
.Application.CommandBars("Mail Merge").Visible = False
With .ActiveDocument
.ShowSpellingErrors = False
.View.ShowFieldCodes = False
.MailMerge.ViewMailMergeFieldCodes = False
.Fields.unlink
.SaveAs Filename:=DocPath & Me![DocFileName]
DoCmd.Close acForm, "PatientDocHistory"
End With
.Application.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set appWord = Nothing
Exit sub
document.
When word is opened instead or reading the document and being left to work
on it the focus of the window comes back to access. I have added these lines
at just before the last end with and still get the problem:
.Application.Visible = True
.WindowState = wdWindowStateMaximize
I have checked the code with break points and nothing runs after this sub is
exited.
Thanks,
Max
Private Sub Button28_Click()
Dim DBPath As String, Template As String, DocPath As String
Dim WordPath As String, TemplatePath As String, Msg As String
Dim appWord As Object 'Word.Application
Dim wdWindowStateMaximize As Long
Dim Quotes As String
wdWindowStateMaximize = 1
Quotes = """"
WordPath = GetWordPath()
TemplatePath = GetTemplatePath()
DocPath = GetDocPath()
WordPath = Quotes & WordPath & Quotes
On Error Resume Next
Template = TemplatePath & Me![DocType].Column(2)
'Get an Application object so you can automate Word.
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
' If no instance running, start word
Set appWord = CreateObject("Word.Application")
End If
'Open a document based on the memo template, turn off the automatic spell
check
DoCmd.Hourglass False
With appWord
.Activate
.Application.Visible = True
.Application.ChangeFileOpenDirectory (DocPath)
.Documents.Add Template
.WindowState = wdWindowStateMaximize
.Application.CommandBars("Mail Merge").Visible = False
With .ActiveDocument
.ShowSpellingErrors = False
.View.ShowFieldCodes = False
.MailMerge.ViewMailMergeFieldCodes = False
.Fields.unlink
.SaveAs Filename:=DocPath & Me![DocFileName]
DoCmd.Close acForm, "PatientDocHistory"
End With
.Application.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set appWord = Nothing
Exit sub