我有两个Comobobx的主要形式。
1. Type of Work (C_Art: Name of Combobox)
Repratur
Maintenance
Optimierung
2. Year (C_Year: Name of Combobox)
2018
2019
在主窗体上有条形图可以很好地工作,而子窗体有数据表视图。
我的问题是,当我选择带有新标题2019-2019年1月-2019年2月...... 2019-Dec的Subform视图时,未更新,并且该行给我错误为#Name?
< / p>
图形生成正确,没有任何问题。
我正在如下更改运行时的查询。
Dim count_Status As String
Dim G_Stoerung As String
'Change the query for Graph
count_Status = "TRANSFORM Count(History_query.[LFD_NR]) AS CountOfLFD_NR " & _
" SELECT History_query.[Anlage] " & _
" FROM History_query " & _
" WHERE History_query.[Anlage] <>Null AND History_query.[WAS]= '" & Me.C_Art & "' AND History_query.[Year]= '" & Me.C_Year & "' " & _
" GROUP BY History_query.[Anlage] " & _
" PIVOT History_query.[Status] "
CurrentDb.QueryDefs("Count_Status_Anlage").sql = count_Status
'Updating the Graph with a new Data
Me.Graph9.Requery
Me!Graph9.ChartTitle.Text = Me.C_Art
'Chnage the query of subform
G_Stoerung = "TRANSFORM Count([History_query].WAS) AS CountOfWAS " & _
" SELECT [History_query].Status " & _
" FROM History_query " & _
" WHERE ((([History_query].WAS)= '" & Me.C_Art & "' ) AND [History_query].Status IN ('Offen','beobachten','In bearbeitung','erledigt') ) " & _
" GROUP BY Status " & _
" Order by (IIf([Status]='Offen',1,IIf([Status]='beobachten',2,IIf([Status]='In bearbeitung',3,IIf([Status]='erledigt',4))))) " & _
" PIVOT Format([Datum],'yyyy-mmm') IN ('" & Me.C_Year & "-Jan','" & Me.C_Year & "-Feb','" & Me.C_Year & "-Mar','" & Me.C_Year & "-Apr','" & Me.C_Year & "-May','" & Me.C_Year & "-Jun','" & Me.C_Year & "-Jul','" & Me.C_Year & "-Aug','" & Me.C_Year & "-Sep','" & Me.C_Year & "-Oct','" & Me.C_Year & "-Nov','" & Me.C_Year & "-Dec') "
CurrentDb.QueryDefs("G_Stoerung_query").sql = G_Stoerung
'Updating the subform with new Data
Me.G_Stoerung_Sub.Form.RecordSource = G_Stoerung
Me.G_Stoerung_Sub.Form.Requery
答案 0 :(得分:0)
#NAME?错误可能是因为文本框不再绑定到存在的字段。使字段名称通用,并为年份应用过滤器参数。或将子窗体容器的SourceObject属性设置为查询对象而不是窗体
修改
G_Stoerung_Sub.SourceObject = ""
G_Stoerung_Sub.SourceObject = "Query.G_Stoerung_query"
更新源对象会得到期望的结果。