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.
Jean-Guy Marcil - 12 Apr 2007 01:15 GMT
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.
[quoted text clipped - 5 lines]
> 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"

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Peter Jamieson - 13 Apr 2007 11:19 GMT
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
>I have a lot of valueable test data (html actually) locked up in a
>sqlserver
[quoted text clipped - 6 lines]
> I've looked for a simple example, but found none. Can someone help with a
> bit of 'How To' sample code.