如附件,我想用窗体组合框列表加一个含VBA代码的Command按扭生成一个不同月份的交叉表查询。CombBox控件"ActExpTabByMth"存放每月不同的表名,Command控件"RNDAcctSplitByProj"中的VBA代码用于生成和查询“RNDAcctsSplitByProject_Apr09”一样格式的每月动态查询。可惜我对VBA代码还不是很熟悉(这些代码我也是参照网友的同类程序依葫芦画瓢,只懂个大概意思 ),尝试了几次均不成功。这个需求的要点是1,组合框控件名作为动态表名;2,要生成一个交叉表查询。恳请各位高手帮忙给指点一下,看如何改动我原来的代码才能达到上述要求。先行谢过了!!作者: RickyZjw-3721 时间: 2009-6-2 23:04
自己重新修改了一下代码如下:可是运行时还是出现错误提示。是否SQL语句不能执行交叉表查询?
Private Sub RNDAcctSplitByProj_Click()
Dim MthExpName As String
Dim Db As DAO.Database
Dim qdf As DAO.QueryDef
Dim StrSql As String
MthExpName = Me.ActExpTabByMth
Set Db = CurrentDb
If MsgBox("是否要拆分实际月份研发费用", vbYesNo, 警告") = vbNo Then Exit Sub
StrSql = "SELECT [MthExpName].Reference, [MthExpName].Acct, AccountsDescription.AcctDescription, [MthExpName].Activ, FROM " _
& "AccountsDescription INNER JOIN MthExpName ON AccountsDescription.Acct = [MthExpName].Acct " _
& "TRANSFORM Sum ([MthExpName].PeriodActivity) AS PeriodActivity " _
& "GROUP BY [MthExpName].Reference, [MthExpName].Acct, AccountsDescription.AcctDescription " _
& "HAVING ((([MthExpName].Activ) Like '6*'))" _
& "PIVOT Format([MthExpName].Activ)"
Set qdf = Db.CreateQueryDef("RNDAcctsSplitByProject", "StrSql")