You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Access 2010数据透视表:仅显示选中行的明细数据

问题需求

我有一个数据库,已创建好Access 2010数据透视表,希望实现:双击数据透视表中的某一行单元格时,仅显示该行对应的明细数据(已能获取双击对象,此部分无问题)。

目前双击行对象时会显示所有明细行,而非仅所需的那一行。由于未来数据量较大(数百行),需要仅展示选中行的明细。尝试过使用监视功能跟踪明细字段,但未取得进展。

当前窗体VBA代码
Option Compare Database

Private Sub Form_Load()
    Me.PivotTable.activedata.hidedetails
End Sub
Private Sub Form_DblClick(Cancel As Integer)
    Dim PTO As Object
    Set PTO = Me.PivotTable
    Set PTO = PTO.ActiveObject

    If (LCase(TypeName(PTO)) <> "nothing") Then
    On Error GoTo endr: ' ignores errors
        Select Case UCase(PTO.Field.Basename)
            Case UCase("Category 1")
                MsgBox Me.PivotTable.ActiveObject.Value, vbOKOnly ' a test to prove double clicking works on category 1
            Case UCase("Category 2")
'            Me.PivotTable.activeobject.expanded = Not Me.PivotTable.activeobject
            
'                Me.PivotTable.activedata
'                PTO.Data.showdetails
'                PTO.axis.Data.DetailLeft =
'                Me.PivotTable.Selection.showdetails
'                PTO.axis.Data.currentcell.Data.showdetails
'                Me.PivotTable.selection.activedata.showdetails
            
                Me.Requery
                MsgBox Me.PivotTable.ActiveObject.Value, vbOKOnly ' a test to prove double clicking works on category 2
'                Me.PivotTable.activeObject.Field.DataField
'                Me.Detail.Visible = Not Me.Detail.Visible
            Case Else
        End Select
    End If

endr:
    Set PTO = Nothing

End Sub
表结构
字段类型
Unique Key文本
Category 1文本
Category 2文本
Values 1数字
Values 2数字
示例数据
Unique KeyCategory 1Category 2Values 1Values 2
test 1-1-1c1sc01123156
test 1-1-2c1sc011563857
test 1-2-1c1sc02657637357
test 1-2-3c1sc036746989876
test 2-0-1c2sc1064763753
test 2-1-1c2sc116873738
数据透视表布局

行区域包含Category 1和Category 2,值区域对Values 1和Values 2进行汇总计算,支持按分组字段折叠行。

补充说明

实际数据包含更多不同值的列,示例仅展示必要的最少数据。未使用带多分组节的连续表单,原因是它不支持折叠功能,且数据量会非常庞大。数据透视表能满足以下需求:

  • 按两个字段分组
  • 对行数据进行汇总计算
  • 可按分组字段折叠行

已知新版本Access不再支持数据透视表,但目前必须使用Access 2010。


内容的提问来源于stack exchange,提问作者cdickstein

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 04:42:14