473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Expression not recognised when using form selections in queries

2 New Member
Hi,

Was wondering if anyone can help. I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go into each query individually and update the criteria to reflect the month I want to analyse by, is there an easy way to change the query criteria once?

I have tried doing this by linking to a form with a combo box getting values from a table with all valid time periods stored in it (which had the disadvantage that the form actually had to be open all the time when running the queries). I've been having problems with this - getting error message saying the jet database engine does not recognise the combo box as a valid field or expression (even when i set it up using the builder rather than typing). Can anyone either help solve this problem or help me with an alternative that would work? E.g storing the value selcted in the combo box in a table and getting to query to run based on that instead - but would only want the current value stored - i.e. each change in the selection from the combo box shoud overwrite anything stored rather than adding a new record - eg if Jan 2004 is selected the first time, and queries run on this basis, i would want all queries to run on this value, until I went into the form and changed it for the following month Feb 2004 - at whioch point would want the queries to use this month not Jan 2004.
Feb 7 '07 #1
5 2258
EricS
2 New Member
Hi,

I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go into each query individually and update the criteria to reflect the month I want to analyse by, is there an easy way to change the query criteria once?

I have tried doing this by linking to a form with a combo box getting values from a table with all valid time periods stored in it (which had the disadvantage that the form actually had to be open all the time when running the queries). I've been having problems with this - getting error message saying the jet database engine does not recognise the combo box as a valid field or expression (even when i set it up using the builder rather than typing). Can anyone either help solve this problem or help me with an alternative that would work? E.g storing the value selcted in the combo box in a table and getting to query to run based on that instead - but would only want the current value stored - i.e. each change in the selection from the combo box shoud overwrite anything stored rather than adding a new record - eg if Jan 2004 is selected the first time, and queries run on this basis, i would want all queries to run on this value, until I went into the form and changed it for the following month Feb 2004 - at which point would want the queries to use this month not Jan 2004.

Help please!
Feb 7 '07 #2
ADezii
8,834 Recognized Expert Expert
Hi,

I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go into each query individually and update the criteria to reflect the month I want to analyse by, is there an easy way to change the query criteria once?

I have tried doing this by linking to a form with a combo box getting values from a table with all valid time periods stored in it (which had the disadvantage that the form actually had to be open all the time when running the queries). I've been having problems with this - getting error message saying the jet database engine does not recognise the combo box as a valid field or expression (even when i set it up using the builder rather than typing). Can anyone either help solve this problem or help me with an alternative that would work? E.g storing the value selcted in the combo box in a table and getting to query to run based on that instead - but would only want the current value stored - i.e. each change in the selection from the combo box shoud overwrite anything stored rather than adding a new record - eg if Jan 2004 is selected the first time, and queries run on this basis, i would want all queries to run on this value, until I went into the form and changed it for the following month Feb 2004 - at which point would want the queries to use this month not Jan 2004.

Help please!
It is a simple matter to change a Query's underlying SQL. Assuming your Query Name is qryTest, then:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.QueryDefs("qryTest").SQL = "SELECT tblEmployees.FirstName FROM " & _
  2.                                      "tblEmployees ORDER BY tblEmployees.FirstName DESC;"
Feb 7 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
How are the dates stored? I'm assuming you're running queries based on
SomeDate BETWEEN DateStart AND DateEnd
If this is the case, then the table must have 2 fields, DateStart and DateEnd. These two fields must be stored as a Date/Time Data Type.
The form then, if you're going to use combo boxes, would need either two combo boxes or one combo box with the end date being calculated from the start date.
Feb 7 '07 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
This was a double post and I have merged both of them together and deleted Rabbits posts pointing to the other post. I agree with Rabbit I think this was accidental.

ADMIN
Feb 8 '07 #5
NeoPa
32,570 Recognized Expert Moderator MVP
Although you can put SQL directly into a QueryDef (See ADezii's post #3) I normally take it out of the QueryDef first, update only the relevant bits, then put it back.
This saves having the full complication of the query being stored in your code.
NB. This is actually a design change to your database, so you should handle multi-user interaction carefully.
Feb 8 '07 #6

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

Similar topics

2
6181
by: Aloof | last post by:
Using Access 2000 Windows Server 2003 The following code worked fine until we moved hosting companies StartDate = Request.Form("StartDateMonth") & "/" & Request.Form ("StartDateDay") & "/" & Request.Form("StartDateYear") EndDate = Request.Form("EndDateMonth") & "/" & Request.Form ("EndDateDay") & "/" & Request.Form("EndDateYear")
18
9042
by: Steve | last post by:
Hi I have a really weird problem and any assistance would be welcome. I have developed an app in Access 2002. The app runs perfectly on the development machine. I have packaged the app using the Microsoft XP Developer Packaging Wizard (Service Pack 1). The 1st 3 releases of the app ran perfectly on site.
3
3302
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string values in it like... Between #12/1/2004# And #12/31/2004# - or - >= #6/10/2005# - or -
3
1904
by: cover | last post by:
Is it possible to use a 'mouse up' click in forms where if you have for example, a drop down menu where you might click as the top selection, an equipment area (hard coded into the form), the type of equipment (a selection of 3 items again hard coded into the form), and then upon 'mouse up' of the second field (equipment type), have the 3rd pull down populated by the mouse up click of the second selection showing database entries available...
2
2469
by: ChasW | last post by:
I just read these 2 pages. These are most helpful, but leave me with a question. http://www.mvps.org/access/queries/qry0005.htm http://www.mvps.org/access/forms/frm0007.htm I have a Multi Select Listbox that will define query criteria for a query that is the record source for another form. Certain individual selections in this list box may act a label for a
10
2583
by: john | last post by:
I have a report to print envelopes. The report is based on a query. Now I need to make 10 more queries to make different selections of addresses. Every query has the same output fields as the already existing query. I know I can copy the report and base it on another query but then I would have to make 10 extra reports. How can I use just one report for all of the queries? At the moment I use the button wizard in my forms to make buttons...
7
7357
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual basic, the value returned is 0. Can anyone tell me why the expression (4 and 1) return different value
6
3530
by: Chris Larmer | last post by:
I have two subforms in my main form. In the main form I want the user to select a customer, class, and date range. The 2 subforms are similar. One is the history records in the recent past and the other is future records. The user has to input a passenger forecast for the customer for the selected class for each record in the date range. The subforms are populated by a query which is altered according to their selection. I wish to...
28
16418
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
0
8823
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
9363
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...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
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...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
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...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
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.