
Data Source Class to access Data Environment
I'm using VB6 SP-1
ADO 2.0
I'm trying to create a component (activex.dll) for all my data access
in an application I'm developing.
This component has a Private Data Environment as well as a public
DataSource class that I'm binding controls to in my main program
component.
This works wonderfully and enables me to distribute all of my data
access seperately from the rest of my application.
The problem I have starts when I try to use Child Commands in my data
environment.
As you know, you can create child commands to create a hierarchical
recordset.
If you have a data environment in the same project, and therefore
within scope of your forms, you bind can Grid1 to the parent command
object and bind Grid2 to the child command object. The result is a
master and detail grid relationship that requires no event coding
within the grids.
I want to duplicate this behavior, but through a Data Source Class.
I have having difficulties getting the detail grid to refresh properly
when I switch records on the master grid.
Sample code is below.
Thank you for your help!
Jeremy Markman
Here is some code I have tried:
Data Source Class:
(cmdDoctorView is a child command to cmdPracticeView)
Option Explicit
' TODO: Declare local ADO Recordset object. For example:
'Private WithEvents rs As ADODB.Recordset
Private GazEnv As envGazelle
Private WithEvents rs As ADODB.Recordset
Dim rs2 As Variant
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
' TODO: Return the appropriate recordset based on DataMember. For
example:
Select Case DataMember
Case "" ' Default
Set Data = rs
Case "cmdPracticeView"
Set Data = rs
Case "cmdDoctorView"
Set Data = rs2
Case Else ' Default
Set Data = Nothing
End Select
End Sub
Private Sub Class_Initialize()
Set GazEnv = New envGazelle
Set rs = GazEnv.rscmdPracticeView
rs.Open
DataMembers.Add "cmdPracticeView"
DataMembers.Add "cmdDoctorView"
End Sub
Private Sub Class_Terminate()
If rs.State = ADODB.adStateOpen Then
rs.Close
Set rs = Nothing
Set rs2 = Nothing
Set GazEnv = Nothing
End If
End Sub
Private Sub rs_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal
pRecordset As ADODB.Recordset)
Set rs2 = rs("cmdDoctorView").Value
End Sub
Code to bind Grids at runtime:
Dim m_PracticeView as GazDataSource.clsDSPracticeView
Private Sub Form_Load()
Set m_PracticeView = New GazDataSource.clsDSPracticeView
With TDBGrid1
.DataMember = "cmdPracticeView"
Set .DataSource = m_PracticeView
End With
With TDBGrid2
.DataMember = "cmdDoctorView"
Set .DataSource = m_PracticeView
End With
End Sub