2013-11-28 40 views
2

任何人都可以在此查看我的代码,看看我做错了什么。我的目标是在创建查询后打开数据表视图中的聚合类型。到目前为止访问数据库通过VBA打开聚集类型

Function LoopQuery(ByVal tempProj As Double) 
Dim strSQL As String 
Dim qdfTemp As QueryDef 
Dim ProjNumb As Double 
ProjNumb = tempProj 
strSQL = "sql code...." 
With CurrentDb 
Set qdfTemp = .CreateQueryDef(ProjNumb, strSQL)  
    qdfTemp.Fields(21).Properties("AggregateType").Value = 0 'add the Aggregate Total on Total Hours 
    qdfTemp.Fields(23).Properties("AggregateType").Value = 0 'add the Aggregate Total on Total Costs 
    qdfTemp.Fields(24).Properties("AggregateType").Value = 0 'add the Aggregate Total on Total Discounted 
End With 

我知道我靠近,我的问题是,

qdfTemp.Fields(21).Properties("AggregateType").Value = 0 'add the Aggregate Total on Hours 
qdfTemp.Fields(23).Properties("AggregateType").Value = 0 'add the Aggregate Total on Total Costs 
qdfTemp.Fields(24).Properties("AggregateType").Value = 0 'add the Aggregate Total on Total Discounted 

不创建总和行,我需要。

我使用这个this在msdn论坛上的财产参考,但它似乎并没有在我的查询工作。任何帮助,将不胜感激。

编辑:

在打转转,我意识到AggregateType.value = 0没有通过,但 “汇总行” wasnt可见。一旦我点击主页功能区中的总记录,我就能够看到它确实得到了我的总结。所以现在我的问题是。

如何在数据表视图的底部设置可见的总计行?我试图

currentdb.qdfTemp.Properties("TotalsRow") = True 

但如你发现,你必须将返回错误

+0

@HansUp您好,感谢回答,在没有的QueryDef得到保存,有没有抛出错误消息这就是为什么单读音混淆。 .createquerydef部分工作,数据库是ACCDB格式 – Eddy

+0

@HansUp我正在使用访问2007年,并且文件是ACCDB,问候。 – Eddy

回答

2

查询的TotalsRow可以显示属性为True所在领域的总数之前。

但是总计行当您第一次创建QueryDef时属性不存在。所以,你必须创建属性...

Set qdfTemp = .CreateQueryDef(ProjNumb, strSQL) 
qdfTemp.Properties.Append _ 
    qdfTemp.CreateProperty("TotalsRow", dbBoolean, True) 
+0

是的,工作!非常感谢你。 – Eddy