msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

QueryString in MailMerge not working

 
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE
Author Message
JediTiger



Joined: 04 Oct 2007
Posts: 2

PostPosted: Wed Jul 13, 2005 1:44 pm    Post subject: QueryString in MailMerge not working Reply with quote

I'm new here so please feel free to point me to another group if this is not
the right one.

I'm using the following VB code to conduct a Mail Merge.

The code is running on XP under MSO 03 (Word VBA6)

This code simply opens the template file (if it is not already open) and
sets up the merge properties and runs the merge.

The extra piece you see, in bold, in the .DataSource.QueryString is my
attempt to get the code to filter the contents of the data file to just those
entries who have 0 for their Owners value.

The part in bold is my problem. It continues to give me a 4198 run-time
error and simply says 'Command Failed'.


Code:
[code]
Sub MergeTest()

Err.Number = 0
On Error GoTo ErrorHandler
Windows("New Ltr-C01.doc").Activate
ErrorHandler:
If Err.Number = 5941 Then
Documents.Open ("X:\Letters\English\Templates\New\New Ltr-C01.doc")
End If
Set letterfile = Documents("New Ltr-C01.doc")

ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
sourcefile = "X:Letters\Data\Test Source File.xls"
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=sourcefile;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDB:"
' connectionstring = "Merge"
' connectionstring = ""
letterfile.CommandBars("Mail Merge").Visible = True
letterfile.MailMerge.MainDocumentType = wdFormLetters
letterfile.MailMerge.OpenDataSource Name:=sourcefile, _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:=connectionstring, _
SQLStatement:="SELECT * FROM `Merge$`", _
SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
With ActiveDocument.MailMerge
[b].DataSource.QueryString = "SELECT * FROM `Merge$` WHERE
`Owners`=`0`" & ""[/b]
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
[/code]

I have tried a variety of ways to state the part in bold:

Code:
[code]
..DataSource.QueryString = "SELECT * FROM `Merge$` WHERE Owners=0"
..DataSource.QueryString = "SELECT * FROM Merge WHERE `Owners`=`0`" & ""
..DataSource.QueryString = "SELECT * FROM `Merge` WHERE `Owners`=`0`" & ""
..DataSource.QueryString = "SELECT * FROM `Merge$` WHERE ((Owners=0))" & ""
[/code]

What I've found on the internet has been nice to read but has not solved my
problem.

So far, nothing is working. Anyone have any ideas?

Thanks! JT

Archived from group: microsoft>public>vb>ole
Back to top
View user's profile Send private message
JediTiger



Joined: 04 Oct 2007
Posts: 2

PostPosted: Tue Jul 19, 2005 3:34 am    Post subject: Re: QueryString in MailMerge not working Reply with quote

No one has any ideas or suggestions on this?

Anyone? Anyone?

JT

On 2005-07-13 11:44:03 -0500, JediTiger
said:

> I'm new here so please feel free to point me to another group if this
> is not the right one.
>
> I'm using the following VB code to conduct a Mail Merge.
>
> The code is running on XP under MSO 03 (Word VBA6)
>
> This code simply opens the template file (if it is not already open)
> and sets up the merge properties and runs the merge.
>
> The extra piece you see, in bold, in the .DataSource.QueryString is my
> attempt to get the code to filter the contents of the data file to just
> those entries who have 0 for their Owners value.
>
> The part in bold is my problem. It continues to give me a 4198 run-time
> error and simply says 'Command Failed'.
>
>
> Code:
> [code]
> Sub MergeTest()
> Err.Number = 0
> On Error GoTo ErrorHandler
> Windows("New Ltr-C01.doc").Activate
> ErrorHandler:
> If Err.Number = 5941 Then
> Documents.Open ("X:\Letters\English\Templates\New\New Ltr-C01.doc")
> End If
> Set letterfile = Documents("New Ltr-C01.doc")
> ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
> sourcefile = "X:Letters\Data\Test Source File.xls"
> connectionstring =
> "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
> Source=sourcefile;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet
> OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:"
> ' connectionstring = "Merge"
> ' connectionstring = ""
> letterfile.CommandBars("Mail Merge").Visible = True
> letterfile.MailMerge.MainDocumentType = wdFormLetters
> letterfile.MailMerge.OpenDataSource Name:=sourcefile, _
> ConfirmConversions:=False, _
> ReadOnly:=False, _
> LinkToSource:=True, _
> AddToRecentFiles:=False, _
> PasswordDocument:="", _
> PasswordTemplate:="", _
> WritePasswordDocument:="", _
> WritePasswordTemplate:="", _
> Revert:=False, _
> Format:=wdOpenFormatAuto, _
> Connection:=connectionstring, _
> SQLStatement:="SELECT * FROM `Merge$`", _
> SQLStatement1:="", _
> SubType:=wdMergeSubTypeAccess
> With ActiveDocument.MailMerge
> [b].DataSource.QueryString = "SELECT * FROM `Merge$` WHERE
> `Owners`=`0`" & ""[/b]
> .Destination = wdSendToNewDocument
> .SuppressBlankLines = True
> With .DataSource
> .FirstRecord = wdDefaultFirstRecord
> .LastRecord = wdDefaultLastRecord
> End With
> .Execute Pause:=False
> End With
> End Sub
> [/code]
>
> I have tried a variety of ways to state the part in bold:
>
> Code:
> [code]
> .DataSource.QueryString = "SELECT * FROM `Merge$` WHERE Owners=0"
> .DataSource.QueryString = "SELECT * FROM Merge WHERE `Owners`=`0`" & ""
> .DataSource.QueryString = "SELECT * FROM `Merge` WHERE `Owners`=`0`" & ""
> .DataSource.QueryString = "SELECT * FROM `Merge$` WHERE ((Owners=0))" & ""
> [/code]
>
> What I've found on the internet has been nice to read but has not
> solved my problem.
>
> So far, nothing is working. Anyone have any ideas?
>
> Thanks! JT

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group