Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Mailmerge with a csv file
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 |
#2
|
|||
|
|||
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 "smh_5" wrote in message ... 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 |
#3
|
|||
|
|||
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? "Peter Jamieson" wrote: 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 "smh_5" wrote in message ... 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to creat relative and shorthand file path names? | Microsoft Word Help | |||
mailmerge - excel datasource - other file extension? | Mailmerge | |||
Using an .odc File to Mailmerge with SQL Server | Mailmerge | |||
mailmerge from excelfile with different file extension | Mailmerge | |||
MailMerge with Access File - need to format currency | Mailmerge |