M
MikeC
I'm attempting to use a dynamic array and I'm having two problems:
1) I can't seem to remember how to append a new row to the array.
Consequently, I seem to be populating only one row at a time as I loop
through my ADODB recordset.
2) A "Subscript out of range" error occurs when I attempt to reference an
array element by row column. However, I *can* successfully reference the
array by column 0 or 1. Perhaps, the solution to problem #1 will also solve
problem #2.
The below code is running in Access 2002 SP3. The O/S is Windows XP SP2.
Can anyone tell me what I'm doing wrong and how to fix it?
Below is the relevant code fragment:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim varPmtDetail() As Variant
With rst1
'Set cursor location to client so that provider will support
RecordCount property.
.CursorLocation = adUseClient
'Open tblPaymentDetail table to read detail records.
.Open strSQL, cnn1, adOpenForwardOnly, adLockReadOnly, adCmdText
.MoveFirst
For i = 0 To .RecordCount - 1
'Loop through recordset and append(?) each pair of values to the
dynamic array.
varPmtDetail = Array(!PmtDetailID, !PartialPaymentAmt)
curTotalPmt = curTotalPmt + !PartialPaymentAmt
'Subscript out of range error occurs on next line.
Debug.Print varPmtDetail(i, 0)
Debug.Print varPmtDetail(i, 1)
'The below debug lines work fine if I comment the above 2 debug
statements.
Debug.Print varPmtDetail(0)
Debug.Print varPmtDetail(1)
.MoveNext
Next i
End With
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1) I can't seem to remember how to append a new row to the array.
Consequently, I seem to be populating only one row at a time as I loop
through my ADODB recordset.
2) A "Subscript out of range" error occurs when I attempt to reference an
array element by row column. However, I *can* successfully reference the
array by column 0 or 1. Perhaps, the solution to problem #1 will also solve
problem #2.
The below code is running in Access 2002 SP3. The O/S is Windows XP SP2.
Can anyone tell me what I'm doing wrong and how to fix it?
Below is the relevant code fragment:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim varPmtDetail() As Variant
With rst1
'Set cursor location to client so that provider will support
RecordCount property.
.CursorLocation = adUseClient
'Open tblPaymentDetail table to read detail records.
.Open strSQL, cnn1, adOpenForwardOnly, adLockReadOnly, adCmdText
.MoveFirst
For i = 0 To .RecordCount - 1
'Loop through recordset and append(?) each pair of values to the
dynamic array.
varPmtDetail = Array(!PmtDetailID, !PartialPaymentAmt)
curTotalPmt = curTotalPmt + !PartialPaymentAmt
'Subscript out of range error occurs on next line.
Debug.Print varPmtDetail(i, 0)
Debug.Print varPmtDetail(i, 1)
'The below debug lines work fine if I comment the above 2 debug
statements.
Debug.Print varPmtDetail(0)
Debug.Print varPmtDetail(1)
.MoveNext
Next i
End With
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<