473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating a query automatically when changing combo box value

119 100+
I have a query that selects data based on a particular date. This date is selected from a combo box on a form. The data from the query is then used to generate a report. This report can be filtered using other features on the form where the date is set.

I am able to modify the query using the date set on the form.

Expand|Select|Wrap|Line Numbers
  1. SELECT AssetPrices.Symbol, Max(AssetPrices.Date) AS MaxOfDate
  2. FROM AssetPrices, PricingDate
  3. WHERE (((AssetPrices.Date)<=[Forms]![frmReportFilter_2].[cboDate].[Value]))
  4. GROUP BY AssetPrices.Symbol;
However, the only way I know how to update the query is by switching the query from table view to design view, and back again. It does not refresh when I select 'refresh' from the Records menu.

Even if I am able to refresh the query by switching views as mentioned above, the changes do not follow through to the report. I have to close the report down and then reload it.

Can anyone suggest a method that will allow the query and report to update dynamically, based on the date selected in the combo box, rather than closing each object down and then reloading it?
Feb 21 '07 #1
7 7611
ADezii
8,834 Expert 8TB
I have a query that selects data based on a particular date. This date is selected from a combo box on a form. The data from the query is then used to generate a report. This report can be filtered using other features on the form where the date is set.

I am able to modify the query using the date set on the form.

Expand|Select|Wrap|Line Numbers
  1. SELECT AssetPrices.Symbol, Max(AssetPrices.Date) AS MaxOfDate
  2. FROM AssetPrices, PricingDate
  3. WHERE (((AssetPrices.Date)<=[Forms]![frmReportFilter_2].[cboDate].[Value]))
  4. GROUP BY AssetPrices.Symbol;
However, the only way I know how to update the query is by switching the query from table view to design view, and back again. It does not refresh when I select 'refresh' from the Records menu.

Even if I am able to refresh the query by switching views as mentioned above, the changes do not follow through to the report. I have to close the report down and then reload it.

Can anyone suggest a method that will allow the query and report to update dynamically, based on the date selected in the combo box, rather than closing each object down and then reloading it?
Try re-opening the Report from the Form in the After Update Event() of cboDate with a where condition as in (assuming Report name is Report1):
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acReport, "Report1", acSaveNo
  2. DoCmd.OpenReport "Report1", acViewPreview, , "[Date] = #" & Me![cboDate] & "#" 
Feb 22 '07 #2
billelev
119 100+
Thanks...I have the report and queries updating using the method you suggested. It seems like a very forced solution though. Is there not a way to update a query without opening/closing each object?
Feb 22 '07 #3
Rabbit
12,516 Expert Mod 8TB
I don't think there's a way, why does it matter if it's being done automatically through code anyways? It should only take all of 2 seconds to accomplish, probably even less.
Feb 22 '07 #4
billelev
119 100+
Elegance...That's all. I'm just surprised that Access doesn't appear to update objects in a more direct way.
Feb 22 '07 #5
NeoPa
32,556 Expert Mod 16PB
Elegance...That's all. I'm just surprised that Access doesn't appear to update objects in a more direct way.
Elegance should never be underestimated.
Elegant solutions have a habit of working more reliably than bodge-fixes.
Elegant code, reused elsewhere, is less likely to fall over due to its inherent consistency.
The Requery procedure can be used to do what you want but I confess to a little confusion as you refer separately to reports and queries. They are different objects (even though a report will often have a record source of a query).
I would also like to confirm my understanding of exactly what you're trying to achieve here - is it that you want a form and a report both to be active at the same time and that making a change to the selection on the form will update the results shown by the report?
Feb 26 '07 #6
billelev
119 100+
Elegance should never be underestimated.
Elegant solutions have a habit of working more reliably than bodge-fixes.
Elegant code, reused elsewhere, is less likely to fall over due to its inherent consistency.
The Requery procedure can be used to do what you want but I confess to a little confusion as you refer separately to reports and queries. They are different objects (even though a report will often have a record source of a query).
I would also like to confirm my understanding of exactly what you're trying to achieve here - is it that you want a form and a report both to be active at the same time and that making a change to the selection on the form will update the results shown by the report?
Sorry for the delay...I have been distracted with other problems. To answer your question, yes, but the report doesn't necessarily have to be open at the same time. Rather, when the report is opened, it should have the required data in it. Here is another example.

I have a form "frmEnterTrade" that populates a table "tblTradeInfo". tblTradeInfo forms the source to part of a query, "qryTradeHistory". The qryTradeHistory query is the source to a report, "rptTradeSummary".

From the user's perspective, data is entered into frmEnterTrade, and that data summarised in the rptTradeSummary report.

However, for newly entered data in frmEnterTrade to appear in rptTradeSummary, the qryTradeHistory query must first be updated. The user obviously isn't concerned with the query, only the inputting of data and viewing the final report.

Access doesn't update a query automatically, hence I need to have code to update the query before opening the report. The only way I know how to do this is by opening and then closing the query. This works, but for more complicated table/query combinations this gets quite clunky, hence my wondering if there is a more elegant method. Especially given that this must be a reasonably common need.
Mar 15 '07 #7
NeoPa
32,556 Expert Mod 16PB
Are you looking for the WhereCondition parameter to the DoCmd.OpenReport() function.
This will allow you to apply a dynamic filter to the underlying query without updating the query (or even the report) permanently.
Mar 15 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
1
by: Gx | last post by:
I have this form with the fields: * Product: (drop down combo box) with choices - X, Y * Amount: (currency ) * Balance (currency) I want to associate product X with the percentage...
3
by: MX1 | last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of parameters that I want to get from combo boxes on a form. One parameter is a date with a dynamically calculated year and...
15
by: Colin | last post by:
I have a query that calculates the selling price of products on customer orders. Selling prices are calculated based on the average cost of the items when purchased. As I make new purchases, the...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
1
by: Efecan | last post by:
Hi, I have the following problem, I created a query SELECT Customer_t.S_Street FROM Customer_t WHERE (((!!)=!)); and used this query to populate a combo box. My customers have multiple...
1
by: Jim | last post by:
I have a form with a combo that is linked to another query. It's my way of getting a value that I need displayed on the form. Only problem is the value isn't there until I select the combo...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.