代码如何写:::最好是用一个函数为好,呵呵,况且能指定某一列数据的总和:
我加载的代码如下:
Private Sub loadData()
Dim strsql As String
strsql = "TRANSFORM Sum(pro_findgx.计划数量) AS 计划数量之Sum " & _
" SELECT pro_findgx.fgxid, pro_findgx.ywid, pro_findgx.id, pro_findgx.下单日期," & _
" pro_findgx.业务日期,pro_findgx.安排日期, pro_findgx.业务单号, pro_findgx.货号, pro_findgx.颜色, " & _
"pro_findgx.工序, Sum(pro_findgx.计划数量) AS [总计 计划数量] FROM pro_findgx " & _
" WHERE (((pro_findgx.fgxid)=1) AND ((pro_findgx.安排日期) Between # " & Me.txtbgn & " # And # " & Me.txtend & " #)) " & _
" GROUP BY pro_findgx.fgxid, pro_findgx.ywid, pro_findgx.id, pro_findgx.下单日期, pro_findgx.安排日期,pro_findgx.业务日期," & _
" pro_findgx.业务单号, pro_findgx.货号, pro_findgx.颜色, pro_findgx.工序 PIVOT pro_findgx.安排日期"
Dim myRs As New ADODB.Recordset
Dim col As Integer, row As Integer, i As Integer, i2 As Integer, lcl As Long
Dim lll As Long
Dim l(3) As Long
Dim ll(3) As Long
'清空listview 控件
Me.ListViewgx1.ColumnHeaders.Clear
Me.ListViewgx1.ListItems.Clear
myRs.Open strsql, CurrentProject.Connection, 3, 1
sql = strsql
col = myRs.Fields.Count
For i = 0 To col - 1
If i = 0 Then
ListViewgx1.ColumnHeaders. _
Add , , Trim(myRs.Fields(i).Name), 0
Else
ListViewgx1.ColumnHeaders. _
Add , , Trim(myRs.Fields(i).Name), ListViewgx1.width / col
End If
Next i
ListViewgx1.ColumnHeaders(1).width = 0
ListViewgx1.ColumnHeaders(2).width = 0
ListViewgx1.View = lvwReport
Dim itmX As ListItem '若当前记录不是最后一条记录,则添加一个 ListItem 对象。
Dim si As ListSubItem
While Not myRs.EOF
Set itmX = ListViewgx1.ListItems. _
Add(, , CStr(myRs(0))) 'menuname 字段。
For i = 1 To col - 1
If Not IsNull(myRs(i)) Then
itmX.SubItems(i) = Trim(CStr(myRs(i)))
End If
Next i
lll = lll + 1
myRs.MoveNext '移动到下一条记录。
For Each si In itmX.ListSubItems
Next si
If lll Mod 1000 = 0 Then DoEvents
Wend
Set si = Nothing
Set itmX = Nothing
myRs.Close
Set myRs = Nothing作者: esther525 时间: 2007-11-26 17:28
另外为何我的LISTVIEW控件的位置老是走动,设计的时候是正确位置,结果视窗的时候就变了位置了..