Thanks for replying. I am not sure what I was doing yesterday but it seems to
work today.
Could you please provide me further guidance. Should I clone the recordset
object used in RecordsetWrapper class as following in by business layer logic
class or should I use pointer to recordset.
The following code I believe is pointing to the recordeset object in
RecordsetWrapper class which I think is similar to By Ref.
Set GetCourseList = rsw.Recordset
The following code is getting the clone of the recordset object in
RecordsetWrapper class which is I think similar to By Value after closing the
source recordset.
If rsw.SetClone(GetCourseList) Then
End If
or is there any other way to get recordset similar to the datareader or
dataset implementation in .Net
RecordsetWrapper: Class Module
===================================================
Option Compare Database
Option Explicit
Private m_rs As ADODB.Recordset
Public Function OpenRecordset(Domain As String, _
Optional Criteria As String = "1=1", _
Optional OrderBy As String, _
Optional RecordsetCursorType As
ADODB.CursorTypeEnum = adOpenForwardOnly, _
Optional RecordsetLockType As
ADODB.LockTypeEnum = adLockReadOnly, _
Optional RecordsetOption As Long = adCmdText, _
) As Boolean
If Not m_rs Is Nothing Then
' Close the recordset so it can be re-used
CloseRecordset
End If
m_rs.Open strSQL, CnxnAIMS, RecordsetCursorType, RecordsetLockType,
RecordsetOption
OpenRecordset = True
Exit Function
ErrorHandler:
' verify the private Recordset object was not set
Debug.Assert m_rs Is Nothing
End Function
Public Property Get Recordset() As ADODB.Recordset
Set Recordset = m_rs
End Property
Public Function SetClone(ByRef rs As ADODB.Recordset) As Boolean
On Error GoTo ErrorHandler
Set rs = m_rs.Clone(adLockReadOnly)
m_rs.Close
SetClone = True
Done:
Set m_rs = Nothing
Exit Function
ErrorHandler:
If eh.LogError("RecordsetWrapper.SetClone") Then Resume
End Function
Private Sub Class_Terminate()
If Not m_rs Is Nothing Then
m_rs.Close
Set m_rs = Nothing
End If
End Sub
===================================================
clsProducts: Class Module
===================================================
Option Compare Database
Option Explicit
Private Const coTABLE As String = "PRODUCTS"
Public Function GetProducts() As ADODB.Recordset
On Error GoTo HandleError
If rsw.OpenRecordset(coTABLE) Then
Set GetCourseList = rsw.Recordset
OR
If rsw.SetClone(GetCourseList) Then
End If
End If
Done:
Exit Function
HandleError:
Err.Raise err.description
End Function
====================================================
Class Implementation in Forms
Dim prd As New clsProducts
Set Me.Recordset = prd.GetProducts()