Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2005

Tip: Looking for answers? Try searching our database.

Mailmerge with a csv file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
smh_5 - 25 May 2005 15:54 GMT
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
Peter Jamieson - 25 May 2005 17:30 GMT
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
> Can someone please point me in the right direction.  I am trying to
> execute a
[quoted text clipped - 24 lines]
>
> Thank you
Sherri - 26 May 2005 15:55 GMT
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?

> 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
[quoted text clipped - 49 lines]
> >
> > Thank you
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.