设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1594|回复: 3
打印 上一主题 下一主题

[Access本身] 求助:在listview控件里,求某一列的总和

[复制链接]
跳转到指定楼层
1#
发表于 2007-11-26 11:05:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在列表框中,我可以编一个函数可求得某一列数据的总和,可是在Listview里我要求得某一列的和为何不行?现需要编一个函数来求和..请高手指教!谢谢
  另:为何我的LIVSVIEW窗口会自动移动呢?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2007-11-26 12:26:53 | 只看该作者
原帖由 esther525 于 2007-11-26 11:05 发表
在列表框中,我可以编一个函数可求得某一列数据的总和,可是在Listview里我要求得某一列的和为何不行?现需要编一个函数来求和..请高手指教!谢谢
  另:为何我的LIVSVIEW窗口会自动移动呢?

y也是我想问的  ,另外楼上的想问一下,列表框求和  代码怎么写?
3#
 楼主| 发表于 2007-11-26 17:21:00 | 只看该作者
原帖由 cuxun 于 2007-11-26 12:45 发表
我想问一下LIVSVIEW是用ado加载的吗?如果是这样的话,你可以在加载的时候计算出该列数据的和,再投到LIVSVIEW上去


代码如何写:::最好是用一个函数为好,呵呵,况且能指定某一列数据的总和:
我加载的代码如下:   
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
4#
 楼主| 发表于 2007-11-26 17:28:05 | 只看该作者
另外为何我的LISTVIEW控件的位置老是走动,设计的时候是正确位置,结果视窗的时候就变了位置了..
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-23 01:05 , Processed in 0.087318 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表