Friday 15 August 2014

vba - SQL Server Passthrough query as basis for a DAO recordset in Access -


We have recently created and migrated our Access DB backend to SQL Server. I am trying to get the VBA code Using, create a connection to the SQL Server backend and run a passbook query with the results stored in a VB record set. When I try this, the question is not being passed. DAO.Database dim RA DAO.Recordset as a dim database in the form of a slow strConnect string strConnect = "driver = sql server, server = 55.55.55.55 SQLExpress; UID = user;

 Name: PWD = Password "set db = OpenDatabase (" dBNAME ", dbDriverNoPrompt, true, strConnect) set rs = db.OpenRecordset (select" GetDate "as qryTest), dbOpenDynaset MsgBox! QryTest rs.Close db.Close set = Anything not set db = nothing   

The problem I am getting is that the proper GetDate () SQL Server Function "The user defined function in the expression 'GetDate' is returning Runtime error 3085. If I make this same question as a passport in the MS Access Access Builder, then it runs fine and gives the server date and time, just in code it is not passing properly.

You can use the QueryDef object to create a pass-through query Required, then the Recordset . The following code works for me:

  In the form of a slow QDF DAO.QueryDef, the first DAO.Recordset set is QDF = CurrentDb.CreateQueryDef ("") qdf .Connect = "ODBC, Driver = SQL Server; Server = \ SQLEXPRESS;. Trusted_Connection = Yes," qdf.SQL = "GetDate () selected as qryTest" qdf.ReturnsRecords = true set first = qdf.OpenRecordset Debug.print first! QryTest rst.Close first set = nothing QDF = nothing is    

No comments:

Post a Comment