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 Chris Miller 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 problem

Status
Not open for further replies.

waely

Programmer
Dec 7, 2003
227
US
hi,
I have a program that has been running for few years and now it started to give this error. the program is an executable; however, I have access to its source code. when troubleshooting I got to this section when the error occures.

-------------------------------
Public Sub InsertLink(varLinkField As Variant)
Dim I, j As Integer
Dim strR As String
strInsertField = ""
strInsertVal = ""

For j = 1 To UBound(varLinkField, 2)
For I = 1 To lngNumCols
If fldName(I) = varLinkField(0, j) Then
Exit For
End If
Next I
strInsertField = strInsertField & ", " & varLinkField(1, j)

//the subscript out of range is with strData((I, lngRowNumber)
strInsertVal = strInsertVal & ", " & fldQuote(I) & strData(I, lngRowNumber) & fldQuote(I)
Next j
End Sub
----------------------------------------------

I'm not sure if the problem with the program itself, which I double, or with the database ....

please help,
Thanks
 
If by chance fldName(I) never = varLinkField(0, j) then I=lngNumCols+1 when you get the error 9.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Which brings up an important point: It is a bad practice to reference a For..Next loop counter variable outside the loop. A better construct would be to declare a separate variable and set it equal to I inside the loop. Example:
Code:
For I = 1 To lngNumCols
  If fldName(I) = varLinkField(0, j) Then
    Index = I
    Exit For
  End If
Next I

where Index is declared as Integer.


Regards,
Mike
 
thanks for the input but it didn't work. could it be something with the database? the program has been working for years and just recently started giving this error message.

thanks
 
Where are varLinkField, lngNumCols, fldName, fldQuote, strData and lngRowNumber coming from ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top