R
Rohan via AccessMonster.com
When I try to use the following code, the word document opens and a list of
tables/queries pops up.
Why ?
Public Sub Prepare_Assessment(dbasequery As String)
'' To automatically set up a word document
'' for the assessment report in the appropriate directory.
'' If assessment has already been prepared it will be opened for viewing in
Word.
Dim objWord As Object, blWordNotRunning As Boolean
On Error Resume Next 'defer error trapping
Set objWord = GetObject(, "Word.Application") 'determine if Word is
running
If Err.number <> 0 Then blWordNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
Set objWord = GetObject(strMergeDoc)
objWord.Application.visible = True
With objWord
.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
Connection:="QUERY " & dbasequery
.MailMerge.Execute
.Application.ActiveDocument.SaveAs strAssessmentDoc
.Application.Documents(strAssessmentDoc).close
If blWordNotRunning Then
' .Application.Quit Savechanges:=wdDoNotSaveChanges
Else
' .Application.Documents(strMergeDoc).close (wdDoNotSaveChanges)
End If
End With
Set objWord = Nothing
End Sub
Cheers,
Rohan.
tables/queries pops up.
Why ?
Public Sub Prepare_Assessment(dbasequery As String)
'' To automatically set up a word document
'' for the assessment report in the appropriate directory.
'' If assessment has already been prepared it will be opened for viewing in
Word.
Dim objWord As Object, blWordNotRunning As Boolean
On Error Resume Next 'defer error trapping
Set objWord = GetObject(, "Word.Application") 'determine if Word is
running
If Err.number <> 0 Then blWordNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
Set objWord = GetObject(strMergeDoc)
objWord.Application.visible = True
With objWord
.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
Connection:="QUERY " & dbasequery
.MailMerge.Execute
.Application.ActiveDocument.SaveAs strAssessmentDoc
.Application.Documents(strAssessmentDoc).close
If blWordNotRunning Then
' .Application.Quit Savechanges:=wdDoNotSaveChanges
Else
' .Application.Documents(strMergeDoc).close (wdDoNotSaveChanges)
End If
End With
Set objWord = Nothing
End Sub
Cheers,
Rohan.