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
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