473,804 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating a query automatically when changing combo box value

119 New Member
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 7674
ADezii
8,834 Recognized Expert Expert
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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,579 Recognized Expert Moderator MVP
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 New Member
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 "frmEnterTr ade" that populates a table "tblTradeIn fo". tblTradeInfo forms the source to part of a query, "qryTradeHistor y". The qryTradeHistory query is the source to a report, "rptTradeSummar y".

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,579 Recognized Expert Moderator MVP
Are you looking for the WhereCondition parameter to the DoCmd.OpenRepor t() 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
4991
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 and 90. The default is set at 30. Question1: When the form opens, there are no records displayed although there are many records that fit the criteria of 30. If I put a button on the form to do a requery and press the button, all the records...
1
7003
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 amount of 50 %, Y with 10
3
7551
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 the other is criteria for a Yes or No field. I'll focus on the Yes/No field for simplicity. If I run the query with the criteria hard coded as either "YES" or "NO", it works. In the values of the combo box in my form, I have it set as...
15
2670
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 product cost changes (as it should) to reflect the new average cost. However, the problem is that the selling price of previously sold items also change when new purchases are made. Keep in mind that I'm not storing any calculated values anywhere....
5
2875
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 but this is probabally a reflection of my not clear understanding of the mechanics behind what i'm trying to achieve. Please bear with it I really could do with your help. I have a simple windows form. There are two controls on the form that I...
0
1928
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 but this is probabally a reflection of my not clear understanding of the mechanics behind what i'm trying to achieve. Please bear with it I really could do with your help. I have a simple windows form. There are two controls on the form that I...
1
1351
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 shipping addresses. When I first open the form and enter the value for a customer name, I get the right values for shipping addresses but when I try to change the customer name, the values for shipping addresses does not change in the combo box. I get...
1
1381
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 manually. How can i get this value to show up in the combo box automatically. The query is tied to date parameters on the form but the form has no record source of its own.
20
5249
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 write the parameter, I want to select a row from the listbox and after clicking in a button, the query to automatically take the current value of listbox as the needed parameter and then to load the query. (The Inputbox for "Enter Parameter" will...
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.