Reply
 
Thread Tools Display Modes
  #1   Report Post  
Al
 
Posts: n/a
Default SQL Database Merge


Greetings,
I would like to merge data from a SQL database. I run the code below in the
word document. However, the form's fields, firstname, and lastname do not
update from FirstName to say Tom, once the "execute" line runs. Am I
missing something to update the form's fields.

Maybe can someone provide working sample code? Thanks in advance.


-- CODE
ActiveDocument.MailMerge.CreateDataSource _
Name:="Pro_Users", _
SQLStatement:="Select * from tblUsers", _
Connection:="Persist Security Info=False;User
ID=xxx;password=psxxx;server=myserver;database=Pro ;", _
LinkToSource:=True

ActiveDocument.MailMerge.Execute
-- END CODE
--


Regards,

Al


  #2   Report Post  
Peter Jamieson
 
Posts: n/a
Default

1. Switch to using an OpenDataSource call instead of CreateDataSource. At
the moment, what is probably happening is that CreateDataSource creates a
Word document called Pro_Users.doc with a standard set of data fields and no
data. It may not even look at the SQLStatement and Connection you have
provided.

2. You have to choose whether to get your data using ODBC or OLEDB,
depending on the version of Word (2002/2003 can use either, before that you
can only use ODBC), and what drivers/providers are available for your
database - if you are using SQL Server, both options are available.

3. For ODBC, you have to create and use a DSN in the ODBC Administrator. You
cannot use a DSN-less connection as far as I know. if you create a Machine
(user/System) DSN called mydsn, you can use

ActiveDocument.MailMerge.OpenDataSource, _
Name:="", _
Connection:="DSN=mydsn;", _
SQLStatement:="Select * from tblUsers"

In Word 2002/2003 you will need to add the parameter

Subtype:=wdMergeSubtypeWord2000

If you create a File dsn called c:\dsns\mydsn.dsn , you will need something
more like

ActiveDocument.MailMerge.OpenDataSource, _
Name:="c:\dsns\mydsn.dsn", _
Connection:="FILEDSN=c:\dsns\mydsn.dsn;", _
SQLStatement:="Select * from tblUsers"

You may also need
a. to add parameters to the Connection string - If you are using a trusted
Connection, you may need to set Trusted_Connection=Yes, otherwise specify
Trusted_Connection=No;UID=xxx;PWD=psxxx; You can also specify the server
(SERVER=), Database (DBQ= or DATABASE=, I forget which off the top of my
head and other stuff)
b. to do stuff like put backquotes round your table name - Select * from
`tblUsers`

4. For OLEDB, you need either to set up a .odc file with the correct
connection info (go through OpenDataSource and in Word 2002/2003 you should
be able to spot the mechanism for doing this) or to specify a completely
empty .odc file and put all the relevant OLEDB connection info. in the
Connection parameter - I would get these from an existing .odc file or .udl
file if you have one.

Peter Jamieson

"Al" wrote in message
...

Greetings,
I would like to merge data from a SQL database. I run the code below in
the word document. However, the form's fields, firstname, and lastname do
not update from FirstName to say Tom, once the "execute" line runs.
Am I missing something to update the form's fields.

Maybe can someone provide working sample code? Thanks in advance.


-- CODE
ActiveDocument.MailMerge.CreateDataSource _
Name:="Pro_Users", _
SQLStatement:="Select * from tblUsers", _
Connection:="Persist Security Info=False;User
ID=xxx;password=psxxx;server=myserver;database=Pro ;", _
LinkToSource:=True

ActiveDocument.MailMerge.Execute
-- END CODE
--


Regards,

Al



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
Mail Merge to a secured Access database Roger Mailmerge 2 May 5th 05 03:21 PM
my Word database is now a merge main document stampinjan Mailmerge 1 March 26th 05 11:20 AM
Mail Merge - DataPerfect database to Word DustyD Mailmerge 1 January 8th 05 09:49 AM
Problem with mail merge and works database techman Mailmerge 2 December 1st 04 04:47 PM
Word mail merge doesn't pick up the addresses in Access database. Julie Tables 1 November 24th 04 01:26 AM


All times are GMT +1. The time now is 11:32 AM.

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"