Access 2007, ADO Library 6.1
I am trying to use a vba function to build an ADODB recordset based on various inputs. I want to return this data to a query in access. However it does not seem to accept an entire recordset from a userdefined function. Here is a very simple example of what I am trying to do with a much more complex VBA recordset:
VBA User defined Function
Query Definition in Access
This of course gives me a syntax error in the FROM clause.
Any ideas how to do this??
-Joshua
If it's not broken, it doesn't have enough parts yet.
I am trying to use a vba function to build an ADODB recordset based on various inputs. I want to return this data to a query in access. However it does not seem to accept an entire recordset from a userdefined function. Here is a very simple example of what I am trying to do with a much more complex VBA recordset:
VBA User defined Function
Code:
Option Compare Database
Option Explicit
Option Base 1
Public Function DetermineUnits() As ADODB.Recordset
Dim rstRecords As ADODB.Recordset
Dim cnnProj As ADODB.Connection
Dim strSQL As String
Set cnnProj = CurrentProject.Connection
strSQL = "SELECT [tblUnits].[ID], [tblUnits].[Abbreviation] FROM tblUnits WHERE [tblUnits].[Measurement Type] < 3 ORDER BY [Abbreviation];"
Set rstRecords = New ADODB.Recordset
rstRecords.Open strSQL, cnnProj
Set DetermineUnits = rstRecords
rstRecords.Close
Set rstRecords = Nothing
End Function
Query Definition in Access
Code:
SELECT * FROM DetermineUnits();
This of course gives me a syntax error in the FROM clause.
Any ideas how to do this??
-Joshua
If it's not broken, it doesn't have enough parts yet.