Can anyone tell me why this code is giving me an error "Subscript out of range" when stuffing data into strArray(6)?
dim strArray(7) as string
Private Sub Form_Activate()
Dim strSQL As String
strSQL = "SELECT * from JournalID"
Dim strDCCode As String
Dim strArray(5) As String
Dim intPos As Integer
Set cnDB = New ADODB.Connection
cnDB.Open "Provider =Microsoft.jet.OLEDB.4.0;data source = c:\rtdglvb6\db1.mdb"
Set rsRec = New ADODB.Recordset
'Open connection to recordset
rsRec.Open strSQL, cnDB, adOpenDynamic, adLockOptimistic
If rsRec.EOF Then
MsgBox "No Records found for this Journal", vbInformation, "General Journal"
Else
rsRec.MoveFirst
intPos = 4
hgOne.Col = 0
'Load selected records to the grid
Do While Not rsRec.EOF
strArray(0) = rsRec!JournalID
strArray(1) = rsRec!AmountType
strArray(2) = rsRec!EffectiveDate
strArray(3) = rsRec!Description
strArray(4) = rsRec!JournalType
strArray(5) = rsRec!totaldebitamount
strArray(6) = rsRec!totalcreditamount 'data present
, but hangs and gives an error 9
'Retrieve fields to Array
hgOne.Row = intPos
For I = 0 To hgOne.Rows - 1
For J = 0 To 6
hgOne.Col = J
hgOne.Text = strArray(J)
Next
If Not rsRec.EOF Then
rsRec.MoveNext
Exit For
End If
Next
intPos = intPos + 1
hgOne.Col = 0
Loop
End If
End Sub
dim strArray(7) as string
Private Sub Form_Activate()
Dim strSQL As String
strSQL = "SELECT * from JournalID"
Dim strDCCode As String
Dim strArray(5) As String
Dim intPos As Integer
Set cnDB = New ADODB.Connection
cnDB.Open "Provider =Microsoft.jet.OLEDB.4.0;data source = c:\rtdglvb6\db1.mdb"
Set rsRec = New ADODB.Recordset
'Open connection to recordset
rsRec.Open strSQL, cnDB, adOpenDynamic, adLockOptimistic
If rsRec.EOF Then
MsgBox "No Records found for this Journal", vbInformation, "General Journal"
Else
rsRec.MoveFirst
intPos = 4
hgOne.Col = 0
'Load selected records to the grid
Do While Not rsRec.EOF
strArray(0) = rsRec!JournalID
strArray(1) = rsRec!AmountType
strArray(2) = rsRec!EffectiveDate
strArray(3) = rsRec!Description
strArray(4) = rsRec!JournalType
strArray(5) = rsRec!totaldebitamount
strArray(6) = rsRec!totalcreditamount 'data present
, but hangs and gives an error 9
'Retrieve fields to Array
hgOne.Row = intPos
For I = 0 To hgOne.Rows - 1
For J = 0 To 6
hgOne.Col = J
hgOne.Text = strArray(J)
Next
If Not rsRec.EOF Then
rsRec.MoveNext
Exit For
End If
Next
intPos = intPos + 1
hgOne.Col = 0
Loop
End If
End Sub