Reply
 
Thread Tools Display Modes
  #1   Report Post  
smh_5
 
Posts: n/a
Default 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   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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   Report Post  
Sherri
 
Posts: n/a
Default

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to creat relative and shorthand file path names? 2dogs Microsoft Word Help 1 May 15th 05 12:11 PM
mailmerge - excel datasource - other file extension? Ralf Pickel Mailmerge 1 February 14th 05 08:05 PM
Using an .odc File to Mailmerge with SQL Server Adam Froio Mailmerge 3 February 10th 05 06:06 PM
mailmerge from excelfile with different file extension Ralf Pickel Mailmerge 0 January 31st 05 08:39 AM
MailMerge with Access File - need to format currency TheMomBon Mailmerge 1 January 26th 05 04:47 PM


All times are GMT +1. The time now is 12:28 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"