Refreshing/requery a query

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Refreshing/requery a query

Post by bknight »

We have discussed refreshing/requiring a form but can the same be done for a query?

Code: Select all

Private Sub Command0_Click()
Call NumberRows
Call CalcProfit(Profit)
Forms("frmNinjaTrader2024_Apex").Requery
Forms("frmNinjaTrader2024_Apex").SetFocus
DoCmd.GoToRecord , , acLast
Forms("frmP_L_By_Symbol_Apex").Requery
DoCmd.Requery "quDailyP_L_Apex"
End Sub
I looked into the process and received a sample from a MS knowledge base, as indicated by the code. However the code line creates an error, no field name in current record.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refreshing/requery a query

Post by HansV »

No, that is not possible, but it shouldn't matter.
Have you opened a query by itself, instead of a form based on a query?
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Refreshing/requery a query

Post by bknight »

The query is opened when the main form of the table is opened. Data loaded, then when the command buttob is clicked the code as you see it attempts to run and the error appears at the line :DoCmd.Requery "quDailyP_L_Apex".
ETA: Looking at the code the main form has focus and just moved to the last record. No field inthat from would equal "quDailyP_L_Apex".
Maybe give focus to the query and then requey?

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refreshing/requery a query

Post by HansV »

Why do you open a query at all?
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Refreshing/requery a query

Post by bknight »

To view the results.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refreshing/requery a query

Post by HansV »

Create a form based on the query and open that instead. You can then requery the form.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Refreshing/requery a query

Post by bknight »

Just another create/modify. No problem.
Thanks

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Refreshing/requery a query

Post by bknight »

HansV wrote:
19 Mar 2024, 20:11
Create a form based on the query and open that instead. You can then requery the form.
What is you reasoning to have a query hidden?

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refreshing/requery a query

Post by HansV »

I never never let users open tables or queries directly to view or edit records; I use forms for viewing/editing records, and reports for viewing in special ways. In a form, you can control what users can and cannot do; in a table or query that is difficult or impossible.
Even in databases for my personal use, I follow the same approach.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Refreshing/requery a query

Post by bknight »

Fair enough.