MSFlexGrid1.ClearMSFlexGrid1.Rows = 2
Dim mrc As ADODB.Recordset
    connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=E:\testpaper\DB\testpaper.mdb"
    dbconn.CursorLocation = adUseClient
    dbconn.Open connstr
    
    txtsql = "select code,outpe,stdes,stanswer,stmemo from testdes"
 Set mrc = dbconn.Execute(txtsql)
 If mrc.EOF = False Then
   mrc.MoveFirst
   With MSFlexGrid1
    .Rows = 4
    .Row = 1
    Do While Not mrc.EOF
     .Rows = .Rows + 1
     For i = 1 To mrc.Fields.Count
      .TextMatrix(.Row, i) = mrc.Fields(i - 1)   '<------实时错误'381' 下标越界!!
     Next i
     .Row = .Row + 1
     mrc.MoveNext
    Loop
 End With
 biaogeshowtitle
    End If
mrc.Close
End Sub

解决方案 »

  1.   

    这段代码是楼上的表格设置模块
     
     
    Public Sub biaogeshowtitle()
    Dim i As Integer
      With MSFlexGrid1
        .Cols = 6
      
        .TextMatrix(0, 1) = "代码"
        .TextMatrix(0, 2) = "人员"
        .TextMatrix(0, 3) = "描述"
        .TextMatrix(0, 4) = "状态"
        .TextMatrix(0, 5) = "备注"
      
        .ColWidth(0) = 0
        .ColWidth(1) = 1000
        .ColWidth(2) = 1072
        .ColWidth(3) = 3500
        .ColWidth(4) = 2500
        .ColWidth(5) = 1200
       
      
        
        .FixedRows = 1
        For i = 1 To 5
          .ColAlignment(i) = 0
        Next i
        .FillStyle = flexFillSingle
        .Col = 0
        .Row = 0
        .RowSel = 1
        .ColSel = .Cols - 1
        .CellAlignment = 4
        .Row = 1
        End With
    End Sub
      

  2.   

      .TextMatrix(.Row, i) = mrc.Fields(i - 1) 
    当i小于等于1的时候不就出错了!