I would like to test converting a pass-through query that uses DAO.QueryDef objects with code to execute a stored procedure which will perform the same SELECT statement. Reason being, I am pushing the upper limit of Access VBA string concatenation building the SQL string.
I came across this article talking about executing SP's with DAO objects:
http://support.microsoft.com/kb/184749
I am wondering how to simply replace sending pass-through SQL in a DAO object and execute the SP instead? That DAO object needs to be able to be referred to by the wrapping DAO.QueryDef object to be able to "SELECT *" from that object targeting a FE temp table as the final destination to place the selected records into.
I have coded up the SP already, now working on building the VBA code to execute the SP. I am using the following shared code to send SELECT SQL to the BE DB and download records into FE temp tables:
I would think I need to adjust the blue code to execute the SP instead, however the article I found about having DAO execute SP's is rather vague about the exact type of DAO object the example code was creating to execute the SP. Was that example even using DAO.QueryDef objects?
TIA!
I came across this article talking about executing SP's with DAO objects:
http://support.microsoft.com/kb/184749
I am wondering how to simply replace sending pass-through SQL in a DAO object and execute the SP instead? That DAO object needs to be able to be referred to by the wrapping DAO.QueryDef object to be able to "SELECT *" from that object targeting a FE temp table as the final destination to place the selected records into.
I have coded up the SP already, now working on building the VBA code to execute the SP. I am using the following shared code to send SELECT SQL to the BE DB and download records into FE temp tables:
Code:
'This API populates the FE temp table via a query of the BE database
Public Function dbutils_RefreshLocalTmpTbl(ByVal strQueryAPIName As String, ByVal strSQLbe As String, ByVal strSQLfe As String) As Boolean
On Error GoTo Err_dbutils_RefreshLocalTmpTbl
Dim daoDB As DAO.Database
Dim daoQDFbe As DAO.QueryDef
Dim daoQDFfe As DAO.QueryDef
Dim strQryNameBE As String
Dim strQryNameFE As String
'Define the name for the BE query
strQryNameBE = "vbaqry" & strQueryAPIName & "_PT"
'Define the name for the FE query
strQryNameFE = "vbaqry" & strQueryAPIName
'Make sure they do not exist, delete the queries we need to build
Call dbutils_DeleteQueryDef(strQryNameBE)
Call dbutils_DeleteQueryDef(strQryNameFE)
'Attach to the FE DB
Set daoDB = CurrentDb()
[COLOR=Blue] 'Build the BE PT Query
Set daoQDFbe = daoDB.CreateQueryDef(strQryNameBE)
With daoQDFbe
.Connect = ObjAppSettings.ODBCConnectString()
.SQL = strSQLbe
.Close
End With[/COLOR]
'Append the name of the BE query onto the FE SQL to complete the FROM clause
strSQLfe = strSQLfe & " " & strQryNameBE & " AS t;"
'Build the FE Query
Set daoQDFfe = daoDB.CreateQueryDef(strQryNameFE)
With daoQDFfe
.SQL = strSQLfe
.Execute
.Close
End With
'Good return code
dbutils_RefreshLocalTmpTbl = True
Exit_dbutils_RefreshLocalTmpTbl:
'Delete the queries we just built
Call dbutils_DeleteQueryDef(strQryNameBE)
Call dbutils_DeleteQueryDef(strQryNameFE)
'Clean up the connection to the database
Set daoDB = Nothing
Set daoQDFbe = Nothing
Set daoQDFfe = Nothing
Exit Function
Err_dbutils_RefreshLocalTmpTbl:
'OK to expect 3325 type errors since an IF might prevent the SELECT from executing
If Err.Number = 3325 Then
dbutils_RefreshLocalTmpTbl = True
Else
'further error handling here for other error types
Call errorhandler_MsgBox("Module: modshared_dbutils, Function: dbutils_RefreshLocalTmpTbl()")
dbutils_RefreshLocalTmpTbl = False
End If
Resume Exit_dbutils_RefreshLocalTmpTbl
End Function
TIA!