PDA

View Full Version : connecting SQL server 2000



deadcat
03-16-2007, 01:57 AM
Hi,
I'm trying to write some VBA for word,
I need to run a query within an SQL DB i have,
and based upon the results of that, compile a document from various other documents.

I can't seem to find how to write the connection string in VBA for word. I've read through the documentation and it seems to connect somehow through the mailmerge object?

any help much appreciated,
Dion

Ken Puls
03-19-2007, 01:56 PM
Hi,
I'm trying to write some VBA for word,
I need to run a query within an SQL DB i have,
and based upon the results of that, compile a document from various other documents.

I can't seem to find how to write the connection string in VBA for word. I've read through the documentation and it seems to connect somehow through the mailmerge object?

any help much appreciated,
Dion

I'm curious... have you tried recording a macro to do it, and see what it gives you?

TonyJollans
03-19-2007, 04:09 PM
I'm not sure what it is you want to do. Mail Merge can use all manner of data sources but you imply that you do not want that and simply want to read from a database into code, in which case the fact that it is Word is not directly relevant. A connection string is the same no matter where it comes from - it is where it is going to that is significant; perhaps this (http://www.connectionstrings.com/) will help.

Ken Puls
03-19-2007, 04:15 PM
I just figured that there must be some Word specifics that I was missing. Thanks for clearing that up, Tony.

If you're just looking to pull a recordset back from a SQL Sever, I'd probably just use an ADO connection. Another source to get the correct connection string (from what Tony mentioned) is Carl Prothman's site: http://www.carlprothman.net/Default.aspx?tabid=81

HTH,

deadcat
03-20-2007, 01:46 AM
looks like it was just me being foolish.

The references to activex are not turned on by default in word, so my connection string variables were not being recognised.

I should be ok now...

:)