Solved

ms/access subform update with refresh/requery

Posted on 2016-11-12
8
39 Views
Last Modified: 2016-11-13
I am facing a challenge with a special subform that I have developed - it does not update to the query to which is bounded.

On the masterform I have some fields that, upon being filled/updated, do generate a set of two sequential queries, the second one being bounded to the subform.

On masterform load everything works fine and the queries based on the updated  fields are ran and output RST is what is expected. However, in the subform, only the original RST is shown. I have Me.refresh / Me.Recalc whenever I update the fields and run the queries. But I do not know to to force the subform refres/recalc/requery (if that is the solution)

can anyone help?
0
Comment
Question by:jirdeaid
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41884877
calling the requery of the subform from the main form,  you have to refer to the subform control

me.[subformcontrolName].form.requery
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41884879
oops, replace the subformControlName with the name of the control where the subform is.
in most cases it is also the name of the subform.
to find the name of the subform control name, open the main form in design view and select the control by clicking on the edge of the subform, hit F4 and on the Other tab look at the Name property and use what is listed there as the name of the subform control
0
 
LVL 20
ID: 41884896
adding on about Name property of a subform control:

If the subform has a caption or information in the autotitle label, it may be used for the name.  Copy what is in the Source Object property to the Name property so they are both the same.  Both of those properties are at the top of the All tab on the Property Sheet for the subform control.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jirdeaid
ID: 41884921
I must be doing something really bad. Just after executing the queries, I conform that the output is OK.

please check the screenshot:


ss1
my code is:



    Debug.Print "Proximidade:" & Me.fld_raioLimite & " metros"
 
    Set Q28_listaProximidadesSet = sireshDB.OpenRecordset("Q28_listaProximidades", dbOpenDynaset)
    strSetSQL = "SELECT Q27_pontosD.codigoTabanca, Q27_pontosD.codigoPonto, Q27_pontosD.TipoPonto, tabancasBase.NomeTabanca, sectoresGuineBissau.nomeSector, regioesGuineBissau.nomeRegia, Q27_pontosD.CalcD "
    strSetSQL = strSetSQL & "FROM (regioesGuineBissau INNER JOIN (Q27_pontosD INNER JOIN tabancasBase ON Q27_pontosD.codigoTabanca = tabancasBase.codigoTabanca) ON regioesGuineBissau.codigoRegiao = tabancasBase.codigoRegiao) INNER JOIN sectoresGuineBissau ON (sectoresGuineBissau.codigoSector = tabancasBase.codigoSector) AND (regioesGuineBissau.codigoRegiao = sectoresGuineBissau.codigoRegiao) "
    strSetSQL = strSetSQL & "WHERE (((Q27_pontosD.CalcD)< "
    strSetSQL = strSetSQL & Nz(Me.fld_raioLimite, 10) & " ));"
    Set Q28_listaProximidadesDef = sireshDB.QueryDefs("Q28_listaProximidades")
    Q28_listaProximidadesDef.SQL = strSetSQL
    Set Q28_listaProximidadesSet = sireshDB.OpenRecordset("Q28_listaProximidades", dbOpenDynaset)
    Me.Refresh
    Me.[sform_listaPontos].Form.Requery


so, just after querying I should see the updated RST.

But now - it always shows the previous RST (!) even when I reload the form..

should it be another method?
0
 
LVL 20

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 100 total points
ID: 41884936
after you change a querydef:

currentdb.querydefs.refresh
DoEvents

then Requery the form
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 400 total points
ID: 41884941
You are just adjusting the SQL of some queries and opening some recordsets unrelated to the subform.

Try this:
strSetSQL = "SELECT Q27_pontosD.codigoTabanca, Q27_pontosD.codigoPonto, Q27_pontosD.TipoPonto, tabancasBase.NomeTabanca, sectoresGuineBissau.nomeSector, regioesGuineBissau.nomeRegia, Q27_pontosD.CalcD "
    strSetSQL = strSetSQL & "FROM (regioesGuineBissau INNER JOIN (Q27_pontosD INNER JOIN tabancasBase ON Q27_pontosD.codigoTabanca = tabancasBase.codigoTabanca) ON regioesGuineBissau.codigoRegiao = tabancasBase.codigoRegiao) INNER JOIN sectoresGuineBissau ON (sectoresGuineBissau.codigoSector = tabancasBase.codigoSector) AND (regioesGuineBissau.codigoRegiao = sectoresGuineBissau.codigoRegiao) "
    strSetSQL = strSetSQL & "WHERE (((Q27_pontosD.CalcD)< "
    strSetSQL = strSetSQL & Nz(Me.fld_raioLimite, 10) & " ));"

Me.[sform_listaPontos].Form.RecordSource = strSetSQL

Open in new window

/gustav
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41884957
check the Record Source of the subform..
is it the query "Q28_listaProximidades"
0
 

Author Closing Comment

by:jirdeaid
ID: 41885159
Hi all! Thanks a lot. Gustav's solution got it working.

Just a side question: I have some unanswered questions. In the old days, after some time (? 48h) I could press a button to request attention to the question. where is this button now?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question