View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
matt matt is offline
external usenet poster
 
Posts: 92
Default Showing a list of SQL Tables under ODBC

Thank you very much for this onedaywhen

Sorry it's taken so long to come back you you I've been
out of the office for a couple of days. When I run the
first bit of code it returns "(local)" and that's it

In my SQL code I refer to the two SQL databases I have as

YOUR-HPBMYE9TMB.SUNDB and
YOUR-HPBMYE9TMB.SUNDB426

So expected to see the YOUR-HPBMYE9TMB bit appear, only
got "(local)" though. Any ideas?

Thank you

Matt


-----Original Message-----
"Matt" wrote ...

Can anyone else help?


There are a couple of issues. First, you must enumerate

available
servers:

Sub test()
Dim oSqlApp As Object
Dim vntName As Variant

Set oSqlApp = CreateObject("SQLDMO.Application")

With oSqlApp
For Each vntName In .ListAvailableSQLServers
Debug.Print vntName
Next
End With

End Sub

To enumerate each database on a server, you first have

to connect to
the server i.e. you need to pass security for that

server.

Assuming you can connect:

Dim oServer As Object
Dim oDatabase As Object
Set oServer = CreateObject("SQLDMO.SQLServer")
With oServer
.Connect "MYSERVER", "MYUID", "MYPASSWORD"
For Each oDatabase In .Databases
Debug.Print oDatabase.Name
Next
End With

--
.