We've recently created and migrated our Access DB backend to SQL Server. I'm trying to, using VBA code, create a connection to the SQL Server backend and run a passthrough query with the results stored in a VB recordset. When I try this, the query is NOT passing through.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strConnect As String
strConnect = "DRIVER=SQL Server;SERVER=55.55.55.55 SQLExpress;UID=UserName;PWD=Password"
Set db = OpenDatabase("DBName", dbDriverNoPrompt, True, strConnect)
Set rs = db.OpenRecordset("SELECT GetDate() AS qryTest", dbOpenDynaset)
MsgBox rs!qryTest
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
The problem I'm getting is that the totally appropriate GetDate()
SQL Server function is returning Runtime Error 3085 "User Defined Function 'GetDate' in expression". If I create this same query as a passthrough in MS-Access Query Builder, outside of VBA code, it runs fine and returns the server date and time, only in code is it not passing through properly.