I couple of days ago I posted a query as to how to program with a recordset to populate MSHflexGrid. A member sent me a code to try. whenever I run the code, there is an error message "runtime error, subscript out of range". Note, I have set reference to the ADO object in code and also using the "NWind" database. Any help would be much appreciated.Attached at the bottom page is the code. Thank you

Albert.


Option Explicit

Private Sub Form_Load()

Dim cnData As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim Char As String
Dim sconnect As String
Dim IRow As Long
Dim i As Integer

Set cnData = New ADODB.Connection
Set rsData = New ADODB.Recordset

cnData.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=F:\Program files\Microsoft Visual studio\Vb98\NWind.mdb"

sconnect = "Select EmployeeId, Lastname from Employees"
cnData.Open

rsData.Open sconnect, cnData, adOpenDynamic
IRow = 1

If rsData.EOF And rsData.BOF Then Exit Sub
MSHFlexGrid1.Cols = rsData.Fields.Count
MSHFlexGrid1.Rows = rsData.RecordCount + 1

Do Until rsData.EOF
For i = 0 To rsData.Fields.Count - 1
MSHFlexGrid1.TextMatrix(0, i) = rsData(i).Name
MSHFlexGrid1.TextMatrix(IRow, i) = rsData(i).Value & " "

Next i
IRow = IRow + 1
rsData.MoveNext
Loop

rsData.Close
cnData.Close
End Sub