Mailmerge with a csv file

S

smh_5

Can someone please point me in the right direction. I am trying to execute a
mailmerge from a vbscript. I need to be able to merge just the record
meeting the criteria (ie. Receipt = 2222). Below is the code I'm trying to
use but I keep getting data not found. Any help would be appreciated even if
I'm doing it all wrong.

Dim doc
Dim wrdApp
set wrdApp = CreateObject("Word.Application")
set doc = CreateObject("Word.Document")
Set doc = GetObject("H:\New samples\merge2.dot")

With doc.MailMerge
.EditDataSource
If .DataSource.FindRecord(FindText=2222, _
Field="Receipt") = True Then
MsgBox "Data was found"
else
MsgBox "Data was not Found"
End If
End With


wrdApp.Visible = True

Thank you
 
P

Peter Jamieson

As a first shot, you might find that surrounding the 2222 by double quotes
helps, but I think you probably need either to re-open the data source using
OpenDataSource, or to re-specify the query using something like

..DataSource.QueryString = "SELECT * FROM <datasource> WHERE Receipt = 2222"
or
..DataSource.QueryString = "SELECT * FROM <datasource> WHERE Receipt =
'2222'"

depending on what type of field Word thinks Receipt is.

The trouble with either of these is that you need to know the exact
parameter values to use in either OpenDataSource or the exact name to
substitute in <datasource> in the above strings - it's fairly easy to
discover these in a particular case by inspecting the existing values of

..DataSource.Name
..DataSource.ConnectString
..DataSource.QueryString

but doing this programmatically and/or in the more general case may be
problematic, particularly in Word XP where an error sometimes prevents you
from inspecting some of these values.

Peter Jamieson
 
S

Sherri

I had tried the double quotes prior with no luck. If I change the select
statement which I would like to do. I do I setup the DSN for a csv file?
 

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