Article ID: 195049
Article Last Modified on 3/14/2005
Function <function_name> as ADODB.Recordsetto a version specific declaration:
Function <function_name> as ADODB.[_Recordset15]There is a previous version specific ProgID exposed for each of the main ADO objects, Recordset, Command, and Connection.
ByVal pRecordset As ADODB.Recordset20Note: Under ADO 2.0, objects were prefaced with an underscore, postfixed with a version identifier and enclosed in square brackets.
Public Function ReturnRS(strConnect As String, _
strQuery As String) As ADODB.Recordset
Dim adoCon1 As New ADODB.Connection
Dim adoRs1 As New ADODB.Recordset
' Set the CursorLocation to adUseClient to return an ADORecordset.
adoCon1.CursorLocation = adUseClient
' Open ADO Connection with passed in connect string.
adoCon1.Open strConnect
' Open ADO Recordset with passed in SQL string.
adoRs1.Open strQuery, adoCon1, adOpenKeyset, adLockBatchOptimistic
' Return ADO Recordset object to Client.
Set ReturnRS = adoRs1
' Can not close the ADO Recordset object here,
' but it can be disassociated.
Set adoRs1.ActiveConnection = Nothing
' Close ADO Connection object.
adoCon1.Close
End Function
Here is the same function modified so that when compiled with a later version of ADO, it
maintains binary compatibility with ADO 1.5:
Public Function ReturnRS(strConnect As String, _
strQuery As String) As ADODB.Recordset15
' Or, Use this syntax for ADO 2.0
' Public Function ReturnRS(strConnect As String, _
' strQuery As String) As ADODB.[_Recordset15]
Dim adoCon1 As New ADODB.Connection
Dim adoRs1 As New ADODB.Recordset
' Set the CursorLocation to adUseClient to return an ADORecordset.
adoCon1.CursorLocation = adUseClient
' Open ADO Connection with passed in connect string.
adoCon1.Open strConnect
' Open ADO Recordset with passed in SQL string.
adoRs1.Open strQuery, adoCon1, adOpenKeyset, adLockBatchOptimistic
' Return ADO Recordset object to Client.
Set ReturnRS = adoRs1
' Can not close the ADO Recordset object here,
' but it can be disassociated.
Set adoRs1.ActiveConnection = Nothing
' Close ADO Connection object.
adoCon1.Close
End Function
The component or application that you compile against the later version of ADO requires the later components to run successfully even if your component or
application only exposes the earlier interfaces. This is common practice when
compiling with dependencies. If you recompile a component with a newer
version of a dependency, the newer dependency becomes a baseline for the
resulting component and you need to redistribute the newer dependency file
with the component. This is no different than recompiling a Visual Basic
application under a newer version of Visual Basic. The resulting
application will not run if you do not distribute the new Visual Basic run-
time .dll with the application.
222145 PRB: ADO Data Control Events May Generate a Compilation Error
Keywords: kbhowto kbdatabase kbcompiler KB195049