I have 4 DNS pass through queries (Access 2010 in a shared folder) that worked fine on my computer, but now new end users at different computers need to use them. I think I understand why this failed on their computer, but I do not want to build a DNS connection for each end user as this changes on a regular basis. I do not have administrative rights so I am trying to build a DNS-less connection to our SQL Server. The pass-through SQL is quite complex and lengthly so I would like to continue to use that stored pass-through query in possible.
This was the SQL string that worked on my computer.
The examples I can find use QueryDefs. I have tried multiple iterations, and I either get the wizard to build a new DNS connection or currently I get a error 3065 which states it cannot execute a SELECT query. I believe the problem is the .Execute.
I am open to current changes or a different direction so any end user with privledges to the Server can run this query.
You don't know what you don't know...
This was the SQL string that worked on my computer.
Code:
strSQL = "INSERT INTO tblGoalINR SELECT * FROM ptqryGoalINR;"
DoCmd.RunSQL(strSQL)
The examples I can find use QueryDefs. I have tried multiple iterations, and I either get the wizard to build a new DNS connection or currently I get a error 3065 which states it cannot execute a SELECT query. I believe the problem is the .Execute.
I am open to current changes or a different direction so any end user with privledges to the Server can run this query.
Code:
Public Sub RunPassThroughQuery()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim qdfNew As DAO.QueryDef
Dim strConnectionString As String
Set db = CurrentDb
Set qdf = db.QueryDefs("ptqryGoalINR")
'Connection string to SQL Server
strConnectionString = "ODBC; Provider=SQLOLEDB.1; Integrated Security=SSPI;Persist Security Info=True;Data Source=MyServer;Initial catalog=MyDatabase"
'Set the DNS-less connection string
'qdf.Connect = strConnectionString
'Create a new temporary QueryDef as an Action query
Set qdfNew = db.CreateQueryDef("", "INSERT INTO tblGoalINR SELECT * FROM ptqryGoalINR;")
'Set the DNS-less connection string
qdfNew.Connect = strConnectionString
'Run Action query with pass-through query
qdfNew.Execute dbFailOnError
' Close connection
qdfNew.Close
' Clean up objects
Set qdf = Nothing
Set qdfNew = Nothing
Exit Sub
End Sub
You don't know what you don't know...