Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

Hope you can help. I have created a mail merge word doc which seems to work
fine. When I close and reload it asks if I wish to pull in the data.
Great.

However, I want to print the results of the mail merge from within a VB.Net
app. I can create and load the word app/doc, but the document is not opened
as a mail merge doc. In fact the mail merge fields just appear as text.

Any ideas please, or alternative was to do this.

many thanks

Chubbly


  #2   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Cindy M -WordMVP-
 
Posts: n/a
Default Mailmerge Automation Problems

Hi Chubbly,

Hope you can help. I have created a mail merge word doc which seems to work
fine. When I close and reload it asks if I wish to pull in the data.
Great.

However, I want to print the results of the mail merge from within a VB.Net
app. I can create and load the word app/doc, but the document is not opened
as a mail merge doc. In fact the mail merge fields just appear as text.

It would help if you'd show us the code you're using... You also need to tell
us which version of Word you're testing on, which versions are targeted, what
type of data source is involved and, if you know, which connection method is
being used.

My best guess would be you're running into this:
"Opening This Will Run the Following SQL Command" Message When You Open a Word
Document - 825765
http://support.microsoft.com?kbid=825765

In an automation environment, where this security measure is activated, you
MUST use the OpenDataSource method to connect the data after the document is
opened. The data source is unlinked without question when a mail merge document
is opened by automation.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

  #3   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

Hi Cindy

Had come round to the fact of using OpenDataSource. Just trying that now,
but unsure what the 'Name' parameter should hold.

I am using VB 2005, Word 2003 and trying to pull in data from an SQL 2005
table.

--------------------------------------
Dim wrdMailMerge As Word.MailMerge

Dim wrdMergeFields As Word.MailMergeFields

Dim wrdSelection As Word.Selection

wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

wrdDoc =
wrdApp.Documents.Open("C:\temp\2005\WordDocument1\ WordDocument1\DeliveryAddress.doc")

wrdDoc.MailMerge.OpenDataSource(Name:="Name", ConfirmConversions:=False,
ReadOnly:=True, LinkToSource:=True, AddToRecentFiles:=False,
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=True,
Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:="data source=WEBDEV;
initial catalog=Subscriptions2; integrated security=SSPI; persist security
info=False; packet size=4096; Connect Timeout=300", SQLStatement:="select *
from subscriptionsprintqueue", SQLStatement1:="",
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)

wrdDoc.MailMerge.Execute()

--------------------------------------


Many thanks

Chubbly


"Cindy M -WordMVP-" wrote in message
news:VA.0000bee5.00a5e089@speedy...
Hi Chubbly,

Hope you can help. I have created a mail merge word doc which seems to
work
fine. When I close and reload it asks if I wish to pull in the data.
Great.

However, I want to print the results of the mail merge from within a
VB.Net
app. I can create and load the word app/doc, but the document is not
opened
as a mail merge doc. In fact the mail merge fields just appear as text.

It would help if you'd show us the code you're using... You also need to
tell
us which version of Word you're testing on, which versions are targeted,
what
type of data source is involved and, if you know, which connection method
is
being used.

My best guess would be you're running into this:
"Opening This Will Run the Following SQL Command" Message When You Open a
Word
Document - 825765
http://support.microsoft.com?kbid=825765

In an automation environment, where this security measure is activated,
you
MUST use the OpenDataSource method to connect the data after the document
is
opened. The data source is unlinked without question when a mail merge
document
is opened by automation.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :-)



  #4   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

I now have the code below. The name in the 'opendatasource' command now
points towards the *.odc file that was created when setting up the mail
merge doc.
When I try to execute, word shows a pop up stating that my merge field does
not exist. Would I like to remove it or use field 'M__' or 'M__1'.?
It appears to be looking at the wrong datasource. If I set the datasource
manually in my document, all works fine.

My code is below again.

thx


wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

wrdDoc =
wrdApp.Documents.Open("C:\temp\2005\WordDocument1\ WordDocument1\DeliveryAddress.doc")

wrdDoc.MailMerge.OpenDataSource(Name:="C:\Document s and Settings\pd.ISL\My
Documents\My Data Sources\webdev Subscriptions2
SubscriptionsPrintQueue.odc", ConfirmConversions:=False, ReadOnly:=True,
LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=True, Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:="data
source=WEBDEV; initial catalog=Subscriptions2; integrated security=SSPI;
persist security info=False; packet size=4096; Connect Timeout=300",
SQLStatement:="select * from subscriptionsprintqueue", SQLStatement1:="",
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)

wrdDoc.MailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument

wrdDoc.MailMerge.Execute()





"Cindy M -WordMVP-" wrote in message
news:VA.0000bee5.00a5e089@speedy...
Hi Chubbly,

Hope you can help. I have created a mail merge word doc which seems to
work
fine. When I close and reload it asks if I wish to pull in the data.
Great.

However, I want to print the results of the mail merge from within a
VB.Net
app. I can create and load the word app/doc, but the document is not
opened
as a mail merge doc. In fact the mail merge fields just appear as text.

It would help if you'd show us the code you're using... You also need to
tell
us which version of Word you're testing on, which versions are targeted,
what
type of data source is involved and, if you know, which connection method
is
being used.

My best guess would be you're running into this:
"Opening This Will Run the Following SQL Command" Message When You Open a
Word
Document - 825765
http://support.microsoft.com?kbid=825765

In an automation environment, where this security measure is activated,
you
MUST use the OpenDataSource method to connect the data after the document
is
opened. The data source is unlinked without question when a mail merge
document
is opened by automation.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :-)



  #5   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

Hi Peter

yes the Word UI can complete the merge.

Have already tried as suggested below, but get the same problem as before
when I either run the Macro from within Word or run the code from within VB.

When I try to execute, word shows a pop up stating that my merge field does
not exist. Would I like to remove it or use field 'M__' or 'M__1'.?

Chubbly

""Peter Huang" [MSFT]" wrote in message
...
Hi Chubbly,

Firstly I assume that you can use Word UI interactive operation to
complete
the MailMerge with the same DB.
I suggest you tried to follow the steps to retrieve the Macro to do mail
merge which is the same as we do in VB.NET.
1. Tools/Macro/Record Macro
2. Start your interactive operation of Mail Merge procedure and complete
that.
3. stop macro record
4. Press Alt+F11 to open the macro you recorded just now.
It should be similar with below.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"path\odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther


This is the code you will use for your VB.NET program.

Please have a try and let me know the result.
Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.





  #6   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

As mentioned, this is what the macro records. When doing this manually, the
doc will merge no problem. When running this macro I get the error.

ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\pd.ISL\My Documents\My Data
Sources\webdev Subscriptions2 SubscriptionsPrintQueue.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
Format:=wdOpenFormatAuto, Connection:= _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=True;Initial Catalog=Subscriptions2;Data Source=webdev;Use Procedure
for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation
ID=WGVWXL1J;Use Encryption for Data=False;Tag with colum" _
, SQLStatement:="SELECT * FROM SubscriptionsPrintQueue", _
SQLStatement1:="", SubType:=wdMergeSubTypeOther



"Chubbly Geezer" wrote in message
...
Hi Peter

yes the Word UI can complete the merge.

Have already tried as suggested below, but get the same problem as before
when I either run the Macro from within Word or run the code from within
VB.

When I try to execute, word shows a pop up stating that my merge field
does not exist. Would I like to remove it or use field 'M__' or 'M__1'.?

Chubbly

""Peter Huang" [MSFT]" wrote in message
...
Hi Chubbly,

Firstly I assume that you can use Word UI interactive operation to
complete
the MailMerge with the same DB.
I suggest you tried to follow the steps to retrieve the Macro to do mail
merge which is the same as we do in VB.NET.
1. Tools/Macro/Record Macro
2. Start your interactive operation of Mail Merge procedure and complete
that.
3. stop macro record
4. Press Alt+F11 to open the macro you recorded just now.
It should be similar with below.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"path\odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
_
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther


This is the code you will use for your VB.NET program.

Please have a try and let me know the result.
Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.





  #7   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Mailmerge Automation Problems

You probably need something more along the following lines. In VBA you
shouldn't need the other parameters (most of them have no effect) but if you
do, put them back


wrdDoc.MailMerge.OpenDataSource(Name:="C:\Document s and Settings\pd.ISL\My
Documents\My Data Sources\webdev Subscriptions2
SubscriptionsPrintQueue.odc", Connection:="Provider=SQLNCLI.1;Data
Source=WEBDEV;Integrated Security=SSPI;Initial Catalog=Subsscriptions2;",
SQLStatement:="select * from ""subscriptionsprintqueue""",
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)

This assumes that you are using the "Native Client" OLEDB provider for SQL
Server 2005 access. You may still be able to use the old provider by
specifying Provider=SQLOLEDB.1 instead. You may need to specify the Data
Source as SERVERNAME\WEBDEV where you substitute your server name.

As long as the Connection and SQLStatement parameters contain everything you
need you can probably get away with a completely empty .odc file.

The double quotes around the table name in the Select statement are probably
optional.

Peter Jamieson

"Chubbly Geezer" wrote in message
...
Hi Peter

yes the Word UI can complete the merge.

Have already tried as suggested below, but get the same problem as before
when I either run the Macro from within Word or run the code from within
VB.

When I try to execute, word shows a pop up stating that my merge field
does not exist. Would I like to remove it or use field 'M__' or 'M__1'.?

Chubbly

""Peter Huang" [MSFT]" wrote in message
...
Hi Chubbly,

Firstly I assume that you can use Word UI interactive operation to
complete
the MailMerge with the same DB.
I suggest you tried to follow the steps to retrieve the Macro to do mail
merge which is the same as we do in VB.NET.
1. Tools/Macro/Record Macro
2. Start your interactive operation of Mail Merge procedure and complete
that.
3. stop macro record
4. Press Alt+F11 to open the macro you recorded just now.
It should be similar with below.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"path\odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
_
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther


This is the code you will use for your VB.NET program.

Please have a try and let me know the result.
Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.





  #8   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Mailmerge Automation Problems

A problem with Word is that it truncates the Connection string when it
records it. If you delete "Tag with colum" from the end, it will probably
work.

Peter Jamieson

"Chubbly Geezer" wrote in message
...
As mentioned, this is what the macro records. When doing this manually,
the doc will merge no problem. When running this macro I get the error.

ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\pd.ISL\My Documents\My Data
Sources\webdev Subscriptions2 SubscriptionsPrintQueue.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=True;Initial Catalog=Subscriptions2;Data Source=webdev;Use Procedure
for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation
ID=WGVWXL1J;Use Encryption for Data=False;Tag with colum" _
, SQLStatement:="SELECT * FROM SubscriptionsPrintQueue", _
SQLStatement1:="", SubType:=wdMergeSubTypeOther



"Chubbly Geezer" wrote in message
...
Hi Peter

yes the Word UI can complete the merge.

Have already tried as suggested below, but get the same problem as before
when I either run the Macro from within Word or run the code from within
VB.

When I try to execute, word shows a pop up stating that my merge field
does not exist. Would I like to remove it or use field 'M__' or 'M__1'.?

Chubbly

""Peter Huang" [MSFT]" wrote in message
...
Hi Chubbly,

Firstly I assume that you can use Word UI interactive operation to
complete
the MailMerge with the same DB.
I suggest you tried to follow the steps to retrieve the Macro to do mail
merge which is the same as we do in VB.NET.
1. Tools/Macro/Record Macro
2. Start your interactive operation of Mail Merge procedure and complete
that.
3. stop macro record
4. Press Alt+F11 to open the macro you recorded just now.
It should be similar with below.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"path\odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
_
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther


This is the code you will use for your VB.NET program.

Please have a try and let me know the result.
Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.







  #9   Report Post  
Posted to microsoft.public.dotnet.languages.vb,microsoft.public.word.mailmerge.fields
Chubbly Geezer
 
Posts: n/a
Default Mailmerge Automation Problems

Many thanks.

Seems the problem went away by removing the Connection and SQLStatement
strings.


"Peter Jamieson" wrote in message
...
You probably need something more along the following lines. In VBA you
shouldn't need the other parameters (most of them have no effect) but if
you do, put them back


wrdDoc.MailMerge.OpenDataSource(Name:="C:\Document s and Settings\pd.ISL\My
Documents\My Data Sources\webdev Subscriptions2
SubscriptionsPrintQueue.odc", Connection:="Provider=SQLNCLI.1;Data
Source=WEBDEV;Integrated Security=SSPI;Initial Catalog=Subsscriptions2;",
SQLStatement:="select * from ""subscriptionsprintqueue""",
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)

This assumes that you are using the "Native Client" OLEDB provider for SQL
Server 2005 access. You may still be able to use the old provider by
specifying Provider=SQLOLEDB.1 instead. You may need to specify the Data
Source as SERVERNAME\WEBDEV where you substitute your server name.

As long as the Connection and SQLStatement parameters contain everything
you need you can probably get away with a completely empty .odc file.

The double quotes around the table name in the Select statement are
probably optional.

Peter Jamieson

"Chubbly Geezer" wrote in message
...
Hi Peter

yes the Word UI can complete the merge.

Have already tried as suggested below, but get the same problem as before
when I either run the Macro from within Word or run the code from within
VB.

When I try to execute, word shows a pop up stating that my merge field
does not exist. Would I like to remove it or use field 'M__' or 'M__1'.?

Chubbly

""Peter Huang" [MSFT]" wrote in message
...
Hi Chubbly,

Firstly I assume that you can use Word UI interactive operation to
complete
the MailMerge with the same DB.
I suggest you tried to follow the steps to retrieve the Macro to do mail
merge which is the same as we do in VB.NET.
1. Tools/Macro/Record Macro
2. Start your interactive operation of Mail Merge procedure and complete
that.
3. stop macro record
4. Press Alt+F11 to open the macro you recorded just now.
It should be similar with below.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"path\odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
_
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther


This is the code you will use for your VB.NET program.

Please have a try and let me know the result.
Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.







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
Error to Automation mailmerge to printer in word 2003 alamas Mailmerge 3 February 2nd 06 06:53 PM
get error 5361 in mailmerge automation sparty1022 Mailmerge 0 September 6th 05 05:03 PM
Mailmerge Querystring Problems hals left Mailmerge 2 August 23rd 05 03:31 PM
Problems with Mailmerge and odc hals left Mailmerge 0 August 9th 05 08:27 PM
Problems (again) getting Outlook contacts in Word 2002 Mailmerge Carl Mailmerge 1 January 21st 05 02:13 AM


All times are GMT +1. The time now is 05:21 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"