How to import data into a word document from sql server express 20

L

Leon Allen

I have a lot of valueable test data (html actually) locked up in a sqlserver
express 2005 database table. I want to access this in word.

I was looking for a word macro, which will connect to the database, and do a
sql select from a colum in a table and display the content in word.

I've looked for a simple example, but found none. Can someone help with a
bit of 'How To' sample code.
 
J

Jean-Guy Marcil

Leon Allen was telling us:
Leon Allen nous racontait que :
I have a lot of valueable test data (html actually) locked up in a
sqlserver express 2005 database table. I want to access this in word.

I was looking for a word macro, which will connect to the database,
and do a sql select from a colum in a table and display the content
in word.

I've looked for a simple example, but found none. Can someone help
with a bit of 'How To' sample code.

Here's some pseudo code opening a database under SQL
and opening a recordset.

Dim rs As New ADODB.Recordset

Set cn = New ADODB.Connection

With cn
.Provider = "SQLOLEDB"
.Open
"Server=ServerName;Database=DatabaseName;Uid=UserName;Pwd=SecretWord;Trusted_Connection=yes"
End With

rs.Open "SELECT MyField FROM MyTable, cn, adOpenKeyset, adLockReadOnly"

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter Jamieson

Another approach is to enable the database toolbar using Tools|Customize and
try inserting your database directly. Although Word initially forces you to
create a .odc (Office Data COnnection) file, you can actually create a
completely empty .odc and put all the connection and query infromationin the
parameters of the DATBASE field.

But make sure you are using Integrated Security, especially if you use the
new SQL client.

Peter Jamieson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top