1
votes

I have a mainform in access with a subform (continous form mode). The subform's source is a query that has a criteria parameter that gets the values from a combobox in mainform.

When I open the mainform, the combobox is empty, and the subform displays all the records. If I select a value in the combobox and click a refresh button that has only the following line of code: me.subformname.form.requery it works fine, and the subforms requeries and refreshes displaying the appropriate records. If I change the value in combobox and hit refresh button, again it requeries/refreshes the subform.

Problem is that if I filter the subfrom using the context menu (Right Click > "Equals to...") the subform is filtered accordingly then I remove the filter (Right Click > "Clear filter from...") the subform is unfiltered, but now if I change the combobox value and hit Refresh button, the subform doesn't refresh nor requery.

The same is true if even if I open the query in the background. Once I filter, refresh doesn't work anymore.

This is the subform query:

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]) ) ); 
1

1 Answers

3
votes

Access can be a bit funny about filtering, especially on subforms.

Try adding explicit code to your Combobox code to clear the filters every time. So it would look something like:

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

Alternatively, you could try dynamically resetting the RecordSource of the subform on every change in the Combobox. (Note that if you do this, you don't have to explicitly requery, as it is done automatically.) So in place of the code you have in the Combobox now, you'd have somthing along the lines of:

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

Hopefully one of those helps you out.