Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 9, subscript out of range

Status
Not open for further replies.

TondoBoy

Programmer
Mar 22, 2001
31
US
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
 
On line one you have DIM strArray(7) as String
On line six you have DIM strArray(5) as String

The program will use the last DIM statement
 
Thanks Nebelmann...I must have been brain dead this morning. Thanks for the help....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top