代码如下:
Public Sub createList(sql As String)
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim rsGird As MSFlexGrid
With rsGrid '设置表头
.TextMatrix(0, 0) = "记录编号"
.TextMatrix(0, 1) = "备件名称"
.TextMatrix(0, 2) = "备件型号"
.TextMatrix(0, 3) = "生产厂家"
.TextMatrix(0, 4) = "所属设备编号"
.TextMatrix(0, 5) = "所属设备名称"
.TextMatrix(0, 6) = "数量"
.TextMatrix(0, 7) = "易损程度"
.TextMatrix(0, 8) = "备注"
For i = 0 To 6 '设置所有表格对齐方式
.ColAlignment(i) = 4
Next i
.ColWidth(0) = 500
.ColWidth(1) = 1800
.ColWidth(2) = 1400
.ColWidth(3) = 1400
.ColWidth(4) = 1400
.ColWidth(5) = 1800
.ColWidth(6) = 400
.ColWidth(7) = 400
.ColWidth(8) = 4500
End With
Set rs = TransactSQL(sql)
If rs.EOF = False Then
With rsGrid '显示信息内容
.Rows = 1
While Not rs.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = rs(0)
.TextMatrix(.Rows - 1, 1) = rs(1)
.TextMatrix(.Rows - 1, 2) = rs(2)
.TextMatrix(.Rows - 1, 3) = rs(3)
.TextMatrix(.Rows - 1, 4) = rs(4)
.TextMatrix(.Rows - 1, 5) = rs(5)
.TextMatrix(.Rows - 1, 6) = rs(6)
.TextMatrix(.Rows - 1, 7) = rs(7)
.TextMatrix(.Rows - 1, 8) = rs(8)
rs.MoveNext
Wend
End With
rs.Close
End If
End Sub