Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Insert Database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
René - 23 May 2005 10:01 GMT
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!
Cindy M  -WordMVP- - 06 Jun 2005 10:49 GMT
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
[quoted text clipped - 23 lines]
>         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 :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.