|
先加columnheaders才能加listitem
Private Sub Form_Load()
Dim syRecset As DAO.Recordset
Dim itemX As ListItem
Dim a As Integer
Dim strSql As String
ListV.ListItems.Clear
strSql = "SELECT * FROM Table1 "
Set syRecset = CurrentDb.OpenRecordset(strSql)
Debug.Print syRecset.RecordCount
For a = 1 To syRecset.Fields.Count
ListV.ColumnHeaders.Add , , syRecset.Fields(a - 1).Name
Next
If syRecset.RecordCount > 0 Then
syRecset.MoveFirst
Do Until syRecset.EOF
Set itemX = ListV.ListItems.Add()
itemX.SubItems(1) = syRecset!AA
itemX.SubItems(2) = syRecset!BB
syRecset.MoveNext
Loop
Set syRecset = Nothing
End If
End Sub |
|