1

我有一个使用子表单(连续表单模式)访问的主表单。子窗体的源是一个查询,它有一个从主窗体中的组合框获取值的条件参数。

当我打开主窗体时,组合框为空,子窗体显示所有记录。如果我在组合框中选择一个值并单击一个只有以下代码行的刷新按钮: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]) ) ); 
4

1 回答 1

3

访问对于过滤可能有点有趣,尤其是在子表单上。

尝试将显式代码添加到您的组合框代码以每次清除过滤器。所以它看起来像:

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

或者,您可以尝试在 Combobox 中的每次更改时动态重置子窗体的 RecordSource。(请注意,如果您这样做,您不必显式地重新查询,因为它是自动完成的。)因此,代替您现在在 Combobox 中的代码,您将拥有以下内容:

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

希望其中之一可以帮助您。

于 2013-04-04T13:56:12.400 回答