I'm having an issue filling a hierarchical recordset with the data from 2 connected recordsets. It's disconnected because I have to create fields that cannot be created in the SQL statements.
Here is the code that does the hard work (and doesn't function for some reason):
rsH.ActiveConnection = "Provider=MSDataShape;Data Provider=None;" '' Data Shaped recordset
rsH.Open "SHAPE APPEND NEW adVarChar(2) as [State], " & _
"((SHAPE APPEND NEW adInteger AS [Unit], " & _
"NEW adSingle AS [State Miles], " & _
"NEW adSingle as [Fuel], " & _
"NEW adSingle AS [MPG], " & _
"NEW adSingle AS [Toll Miles], " & _
"NEW adVarChar(2) as [State]) " & _
"AS CHILD RELATE [State] TO [State])", , adOpenStatic, adLockOptimistic
Set rsTemp = GetRecordset(SQL)
If Not rsTemp.EOF Then
rsTemp.MoveFirst
While Not rsTemp.EOF
rsH.AddNew "State", rsTemp![FD_STATE]
rsH.Update
rsTemp.MoveNext
Wend
rsH.MoveFirst
Else
QuarterlyReport = False
Exit Function
End If
Set rsHCh = rsH("Child").Value
Set rsTemp = GetRecordset(SQL)
If Not rsTemp.EOF Then
rsTemp.MoveFirst
While Not rsTemp.EOF
sMPG = 0 'rsTemp![SumOfFD_TOT_MILES] / rsTemp![SumOfFD_FUEL]
rsHCh.AddNew
rsHCh![Unit] = rsTemp![FD_UNIT]
rsHCh![State Miles] = rsTemp![SumOfFD_TOT_MILES]
rsHCh![Fuel] = rsTemp![SumOfFD_FUEL]
rsHCh![MPG] = 0
rsHCh![Toll Miles] = rsTemp![SumOfFD_TOLL_MILES]
rsHCh![State] = rsTemp![FD_STATE]
rsHCh.Update
rsTemp.MoveNext
Wend
Else
QuarterlyReport = False
Exit Function
End If
The SQL statements are left out just for ease of reading, but they function properly, and the GetRecordset function simply takes in the SQL string and returns the recordset from it.
What is happening is that only the first or last record in the parent recordset is being linked with the child recordset. All other records from the child are lost.
For instance, say record 1 in the parent is equal to CT and there are 78 records in the child that match CT, then there are only 78 records added to the child...not the full 998 records in the recordset.
The code that I am using mimics exactly the code in another application I wrote that works fine. The only difference is the fields in the recordsets are different. Everything else is exactly the same. Any ideas what might be happening?
Also, one more thing. I did check the contents of the parent recordset, and all the records are in there that should be in there. Both SQL statements pull from the same table using the same selection parameters, just different fields are returned.
Here is the code that does the hard work (and doesn't function for some reason):
rsH.ActiveConnection = "Provider=MSDataShape;Data Provider=None;" '' Data Shaped recordset
rsH.Open "SHAPE APPEND NEW adVarChar(2) as [State], " & _
"((SHAPE APPEND NEW adInteger AS [Unit], " & _
"NEW adSingle AS [State Miles], " & _
"NEW adSingle as [Fuel], " & _
"NEW adSingle AS [MPG], " & _
"NEW adSingle AS [Toll Miles], " & _
"NEW adVarChar(2) as [State]) " & _
"AS CHILD RELATE [State] TO [State])", , adOpenStatic, adLockOptimistic
Set rsTemp = GetRecordset(SQL)
If Not rsTemp.EOF Then
rsTemp.MoveFirst
While Not rsTemp.EOF
rsH.AddNew "State", rsTemp![FD_STATE]
rsH.Update
rsTemp.MoveNext
Wend
rsH.MoveFirst
Else
QuarterlyReport = False
Exit Function
End If
Set rsHCh = rsH("Child").Value
Set rsTemp = GetRecordset(SQL)
If Not rsTemp.EOF Then
rsTemp.MoveFirst
While Not rsTemp.EOF
sMPG = 0 'rsTemp![SumOfFD_TOT_MILES] / rsTemp![SumOfFD_FUEL]
rsHCh.AddNew
rsHCh![Unit] = rsTemp![FD_UNIT]
rsHCh![State Miles] = rsTemp![SumOfFD_TOT_MILES]
rsHCh![Fuel] = rsTemp![SumOfFD_FUEL]
rsHCh![MPG] = 0
rsHCh![Toll Miles] = rsTemp![SumOfFD_TOLL_MILES]
rsHCh![State] = rsTemp![FD_STATE]
rsHCh.Update
rsTemp.MoveNext
Wend
Else
QuarterlyReport = False
Exit Function
End If
The SQL statements are left out just for ease of reading, but they function properly, and the GetRecordset function simply takes in the SQL string and returns the recordset from it.
What is happening is that only the first or last record in the parent recordset is being linked with the child recordset. All other records from the child are lost.
For instance, say record 1 in the parent is equal to CT and there are 78 records in the child that match CT, then there are only 78 records added to the child...not the full 998 records in the recordset.
The code that I am using mimics exactly the code in another application I wrote that works fine. The only difference is the fields in the recordsets are different. Everything else is exactly the same. Any ideas what might be happening?
Also, one more thing. I did check the contents of the parent recordset, and all the records are in there that should be in there. Both SQL statements pull from the same table using the same selection parameters, just different fields are returned.