Insert Database

R

René

Hello,

In MS Word I want to query (using MS Query) a database and insert the
results in a table. I have recorded the actions in a macro. This works fine
so far.
But when I want to run the macro again, there is still an action I have to
do by hand.

Below you'll find the code. When I run this code I still need to select a
datasource and click the 'Open' button. How can I alter the code so that
clicking 'Open' is not necessary?

Sub Macro()
Dim strT As String
strT = "Topology"
Selection.Range.InsertDatabase Format:=0, Style:=0, LinkToSource:=True, _
Connection:= _
"DSN=RAM
ODBC;ARServer=server;ARServerPort=1234;UID=xxxxx;PWD=xxxx;ARAuthentication=;ARUseUnderscores=1;ARNameReplace=1;SERVER=NotTheServer" _
, SQLStatement:= _
"SELECT strT.Status, strT.Relationship, strT.Parent_Name,
strT.Parent_ID, strT.Child_Name, strT.Child_ID FROM strT strT WHERE " _
& _
"(strT.Parent_Name Like 'Test%') ORDER BY strT.Parent_Name" _
, PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", DataSource:="", From:=-1, To:=-1, _
IncludeFields:=True
End Sub

Thanks!
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?UmVuw6k=?=,

Which version of Word is this?
In MS Word I want to query (using MS Query) a database and insert the
results in a table. I have recorded the actions in a macro. This works fine
so far.
But when I want to run the macro again, there is still an action I have to
do by hand.

Below you'll find the code. When I run this code I still need to select a
datasource and click the 'Open' button. How can I alter the code so that
clicking 'Open' is not necessary?

Sub Macro()
Dim strT As String
strT = "Topology"
Selection.Range.InsertDatabase Format:=0, Style:=0, LinkToSource:=True, _
Connection:= _
"DSN=RAM
ODBC;ARServer=server;ARServerPort=1234;UID=xxxxx;PWD=xxxx;ARAuthentication=;ARUseUnderscores=1;ARNameReplace=1;SERVER=NotTheServer" _
, SQLStatement:= _
"SELECT strT.Status, strT.Relationship, strT.Parent_Name,
strT.Parent_ID, strT.Child_Name, strT.Child_ID FROM strT strT WHERE " _
& _
"(strT.Parent_Name Like 'Test%') ORDER BY strT.Parent_Name" _
, PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", DataSource:="", From:=-1, To:=-1, _
IncludeFields:=True
End Sub

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 :)
 

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