SQL ODBC Connection

R

rich19k83

Hello,

I am using the below code to connect to an SQL server in Excel 2003 and run
a query. The code works fine and runs the query, but the only problem is that
I have to manually click ok to select the server & click ok to confirm the
user ID and Password, even though its already been enetered. Is there a way
to automate this so it runs without any user interacton?


Dim varConn As String
Dim varSQL As String
varConn = "ODBC;DSN= Sql_Server;UID=" & Range("J2") & ";PWD=" &
Range("J2")
varSQL = Range("H2")
With ActiveSheet.QueryTables.Add(Connection:=varConn,
Destination:=Range("A1"))
.CommandText = varSQL
.Name = "Query-39008"
.Refresh BackgroundQuery:=False
End With


Thanks
 

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