Mail merge problem

  • Thread starter Rohan via AccessMonster.com
  • Start date
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.
 
L

Larry Daugherty

set a breakpoint on the first executable statement in your code.
Single step through your code until something breaks.

Enjoy your troubleshooting.

HTH
 
R

Rohan via AccessMonster.com

Larry said:
set a breakpoint on the first executable statement in your code.
Single step through your code until something breaks.

I've done this. The line :

With objWord
.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
Connection:="QUERY " & dbasequery

Brings up the word document, but instead of passing through QUERY dbasquery,
and merging the
documents, it brings up a list of tables/queries to select from (without the
dbasquery, strangely enough).

Help!

Rohan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top