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 / December 2006

Tip: Looking for answers? Try searching our database.

Help with Insertdatabase command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Liam - 17 Dec 2006 20:29 GMT
Hi there

With some help from user forum postings I have got the following command to
retreive information from an sql database and use it to populate fields in a
userform.

The trouble i am having is that when the code is executed, I cannot stop the
'Select Data Source' Window from appearing. The three choices that are
presented are +Connect to new data source, +Connect to SQL server connection
and +Thumbs. The first is highlihghted by defualt, and the user just needs to
hit <Return> for the code to continue to run, but i would prefer that this
user intervention was not required. Any thoughts gratefully appreciated.

Here is the code i am using-

 
   oLogin = "DSN=clients;Driver=Firebird/InterBase(r) driver;Dbname=" & _
           "srv01:e:\ibdata\live.fdb;CHARSET=NONE;PWD=CA;UID=RO"
             
   oSQL = "SELECT CLIENTS.CL_KEY, CLIENTS.CL_NAME " & _
           " WHERE CLIENTS.CL_KEY='" & code & "'"
       
Selection.Range.InsertDatabase LinkToSource:=False, Connection:=oLogin, _
       SQLStatement:=oSQL, IncludeFields:=False

Signature

With best regarads

Liam

Peter Jamieson - 18 Dec 2006 09:46 GMT
As far as I am aware, you have to provide InsertDatabase with a file name
(and it will almost certainly have to be a file you can reach on a local
device or via Windows networking, not an Internet URL) in the Datasource
parameter, regardless of whether or not the connection string provides
everything you need to connect to your data source.

In this case, the only thing that is likely to work is to create a file dsn
for your data source, let's call it

"c:\mydsns\ibdsn1.dsn"

and use, something like:

oDataSource = "c:\mydsns\ibdsn1.dsn"
oLogin = "FILEDSN=" & oDataSource & ";PWD=CA;UID=RO"
oSQL = "SELECT CLIENTS.CL_KEY, CLIENTS.CL_NAME " & _
            " WHERE CLIENTS.CL_KEY='" & code & "'"
Selection.Range.InsertDatabase _
 LinkToSource:=False, _
 Connection:=oLogin, _
 SQLStatement:=oSQL, _
 DataSource:=oDataSource, _
 IncludeFields:=False

Since file DSNs are plain text files, they are reasonably easy to create "on
the fly" should you need to do so, but if you end up doing that, it's very
important that the driver name in the DSN matches the driver name on the
machine where the code is running.

No, I don't think this stuff is properly documented anywhere, and of course
that means there could well be a way to do it without a file DSN...

Peter Jamieson

> Hi there
>
[quoted text clipped - 24 lines]
> Selection.Range.InsertDatabase LinkToSource:=False, Connection:=oLogin, _
>        SQLStatement:=oSQL, IncludeFields:=False

Rate this thread:






 
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.