XP - OLE Automation not working

S

stewartj

I have an Access data project, one feature of which is to
allow my users, after revising their data, to click a
button which invokes Word to print a group of mail merge
letters.
This has been working perfectly for a couple of years.
Sometime in the past year, we moved from Office 2000 to
Office-XP. Last week we had to make a change to the
letter and it was necessary to reconnect the data
source. In XP, I now had to use the .odc file instead of
a .dsn file to establish the data source for the merge.
The problem is that the Access code uses ole automation
and used to change the filter on the datasource using the
querystring method. What I had been doing no longer
works. I get the message 'Command Failed' when I try to
execute the line of code

objWord.ActiveDocument.MailMerge.DataSource.QueryString =
strSource

Is there another way to filter the data source with XP? I
have tried a variety of things with no success.

The whole section of code (in Access) looks like this:
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim strDocName As String
Dim strWhere As String
Dim strSource As String
Dim objWord As New Word.Application

If grpCategory.Value = 1 Then
strDocName = gEvalMemoPath & "TEAMS-E.doc"
ElseIf grpCategory.Value = 2 Then
strDocName = gEvalMemoPath & "TEAMS-N.doc"
Else
strDocName = gEvalMemoPath & "USPS.doc"
End If
strWhere = mSetCriteria()

strSource = "Select * from
Personnel.dbo.vwEvalTeamsUSPS " & strWhere

'Open Word without showing it. Open the memo document
' which has vwEvalTeamsUSPS as its mail merge source

objWord.Documents.Open FileName:=strDocName

'Change the query options in Word to filter the query

objWord.ActiveDocument.MailMerge.DataSource.QueryString =
strSource

'Run the Word Macro which merges data with form and prints

objWord.Run MacroName:="MergeTest"

Set objWord = Nothing

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
 

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