本文介绍了Access子窗体不刷新显示的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access中有一个主窗体和一个子窗体(连续窗体模式)。子窗体的源是一个具有Criteria参数的查询,该参数从MainForm中的组合框中获取值。

打开主窗体时,组合框为空,子窗体显示所有记录。如果我在组合框中选择一个值并单击一个刷新按钮,该按钮只有下面一行代码:me.subformname.form.requery,它可以很好地工作,并且子窗体重新查询并刷新显示相应的记录。如果我更改组合框中的值并点击刷新按钮,它将再次重新查询/刷新子窗体。

问题是,如果我使用上下文菜单筛选出子窗体(Right Click > "Equals to...")子窗体被相应地筛选,那么我删除筛选器(Right Click > "Clear filter from...")子窗体未被筛选,但现在如果我更改组合框值并点击刷新按钮,子窗体既不刷新也不重新查询。

即使我在后台打开查询,也是如此。一旦我进行筛选,刷新就不再起作用。

这是子窗体查询:

SELECT qry_listatoatesesizarile.idsesizare,
       branduri.numebrand,
       locatii.fsname,
       categoriiechipamente.categorieechipament,
       echipamente.codechipament,
       qry_listatoatesesizarile.nrsesizare,
       qry_listatoatesesizarile.datasesizare,
       qry_listatoatesesizarile.datasla,
       qry_listatoatesesizarile.detalii,
       qry_listatoatesesizarile.stare,
       Dlookup("[stareraport]", "listastarirapoarte",
       "[idstareraport]=" & [stare]) AS
       StareS,
       echipe.denumireechipa
       AS EchipaLocatie,
       qry_listarapoarte.nrraport,
       qry_listarapoarte.datainceput,
       qry_listarapoarte.datafinalizat,
       qry_listarapoarte.lucrariefectuate,
       qry_listarapoarte.cauzadefectiune,
       qry_listasesizariprogramate.denumireechipa
       AS EchipaProgramata,
       Iif([stare] = 1
            OR [stare] = 3
            OR [stare] = 0, Datediff("s", Cdate([datasla]), Now()),
       Datediff("s", Cdate([datasla]), Cdate([datafinalizat])))
       AS DiferentaSLASecs,
       Secs2dhms([diferentaslasecs])
       AS DiferentaSLA,
       Iif([diferentaslasecs] < 0, true, false)
       AS InSLA,
       Format([datasesizare], "mmmm yyyy")
       AS [Month],
       Iif([stare] = 2
            OR [stare] = 4, Iif([diferentaslasecs] < 0, "inchis in sla",
                            "inchis in afara sla"),
       Iif([diferentaslasecs] < 0, "deschis in sla", "deschis in afara sla"))
       AS
       Situatie,
       locatii.clientfrigorifice,
       clienti.client
FROM   clienti
       INNER JOIN (((((branduri
                       INNER JOIN ((qry_listatoatesesizarile
                                    INNER JOIN echipamente
                                            ON
qry_listatoatesesizarile.idechipament =
echipamente.idechipament)
                                   INNER JOIN locatii
                                           ON echipamente.idlocatie =
                                  locatii.idlocatie)
                               ON branduri.idbrand = locatii.idbrand)
                      INNER JOIN categoriiechipamente
                              ON echipamente.idcategorieechipament =
                                 categoriiechipamente.idcategorieechipament)
                     INNER JOIN echipe
                             ON qry_listatoatesesizarile.idechipa =
                                echipe.idechipa)
                    LEFT JOIN qry_listasesizariprogramate
                           ON qry_listatoatesesizarile.idsesizare =
                              qry_listasesizariprogramate.idsesizare)
                   LEFT JOIN qry_listarapoarte
                          ON qry_listatoatesesizarile.idraport =
                             qry_listarapoarte.idraport)
               ON clienti.idclient = locatii.clientfrigorifice
WHERE  ( ( ( Format([datasesizare], "mmmm yyyy") ) LIKE Iif(Nz(
                    [forms] ! [controlsla] ! [cb_lunaverificata], "") = "", "*",
                      [forms] ! [controlsla] ! [cb_lunaverificata]) )
         AND ( ( locatii.clientfrigorifice ) LIKE Iif(Nz(
               [forms] ! [controlsla] ! [cb_client]
                                                      ,
                                                          "") = "", "*",
               [forms] ! [controlsla] ! [cb_client]) ) ); 

推荐答案

Access可能会对筛选感到有点好笑,尤其是在子窗体上。

尝试将显式代码添加到组合框代码中,以便每次都清除过滤器。因此,它看起来如下所示:

Me.subformname.Form.Filter = Null
Me.subformname.Form.FilterOn = False
Me.subformname.Form.Requery

或者,您可以尝试在组合框中的每个更改时动态重置子窗体的RecordSource。(请注意,如果这样做,则不必显式重复查询,因为它是自动完成的。)因此,取代现在组合框中的代码,您将获得类似以下内容的代码:

Dim mySQLString as String

'Store subform query
mySQLString = "SELECT qry_listato... <<The rest of your query here>>>"

'Set Subform RecordSource
Me.subformname.Form.RecordSource = mySQLSTring

希望其中一个能帮到您。

这篇关于Access子窗体不刷新显示的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:43