View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
rich19k83 rich19k83 is offline
external usenet poster
 
Posts: 1
Default SQL ODBC Connection

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