473,441 Members | 1,331 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,441 software developers and data experts.

Default Where criteria for Queries

41
Hello,

I am stuck with a problem here.

I am building a database and I have several filter queries.

In most of those queries I do a "Where" filter with always the same criteria, being something like:
Expand|Select|Wrap|Line Numbers
  1. <>"AAAA" And <>"BBBB"
I may want to change this criteria later on.

Is there any way to assign a constant value for this criteria for the whole database so that, if I change it, I do not need to change several queries but only one line of code only?

I have been looking on the internet for a solution and tryed different things on access/VBA but couldn't come up with something that works.

If you need more info on my request please let me know and thank you very much for your help.

Best regards,

G.
Aug 23 '07 #1
5 1194
Have a table with one record at a time and just do a Dlookup for the critira you should be able to put the dlookups right into the query but if not just hide text boxes on your forms set to the dlookups that way all you have to do is change the data in that on record you can even make a form so that the end user can do so.
Aug 23 '07 #2
Gari
41
Hello,

First of all thanks for your reply.

I have tried as you suggested the Dlookup inserted directly in the query.

I have created a table called [Restrictions] with 2 fields: [ID], [Statusrestrict]. with one record as follows: [ID]= 1 and [Statusrestrict]=<>"AAA" And <>"BBB"

In the query I call:

Expand|Select|Wrap|Line Numbers
  1. DLookup("[Statusrestrict]", "Restrictions", "[ID]=1")
And my query looks like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblProspects.CompName, tblProspects.Status
  2. FROM tblProspects
  3. WHERE (((tblProspects.Status)=DLookUp("[Statusrestrict]","Restrictions","[ID]=1")))
  4. GROUP BY tblProspects.CompName, tblProspects.Status;
However, when I run the query, it does not read the value in [Statusrestrict] and it returns nothing.

Anyone can help?

Thank you very much.

Best regards,

G.
Aug 25 '07 #3
Scott Price
1,384 Expert 1GB
Try changing your Dlookup statement from this:
Expand|Select|Wrap|Line Numbers
  1. DLookup("[Statusrestrict]", "Restrictions", "[ID]=1")
To this:
Expand|Select|Wrap|Line Numbers
  1. DLookup("[Statusrestrict]", "Restrictions")
If this doesn't work, you might have some misspelling somewhere that 'tis making the lookup not find the field and/or table referred to, or is returning a value from the table restrictions that is causing the main query to return no records.

To debug this, try running a simple select query using the table "Restrictions" to see what data it returns for the ID = 1 criteria. Then make sure you have data in the table queried by your main query that matches the value returned by your second test query.

Regards,
Scott
Aug 25 '07 #4
Gari
41
Hello,

I have tried as you said but it does not work either.

I feel that there is a problem of syntax in the code as when you build up the query in access, it puts by default an "=" into the code for the criteria field if nothing else is specified.

So my original query (the one that does not work) looks like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblProspects.CompName, tblProspects.Status
  2. FROM tblProspects
  3. WHERE (((tblProspects.Status)=DLookUp("[Statusrestrict]","Restrictions","[ID]=1")))
  4. GROUP BY tblProspects.CompName, tblProspects.Status;
In my table field [Statusrestrict], I have this data:

Expand|Select|Wrap|Line Numbers
  1. <>"AAA" And <>"BBB"
Then I have tried to put only one criteria in the field, that is to say that I tried with [Statusrestrict]=AAA and the code:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblProspects.CompName, tblProspects.Status
  2. FROM tblProspects
  3. WHERE (((tblProspects.Status)<>DLookUp("[Statusrestrict]","Restrictions","[ID]=1")))
  4. GROUP BY tblProspects.CompName, tblProspects.Status;
This actually is working very fine, but only with a single data to be filtered out. And in my case, I need to filter two or more data, without having to go through all the queries if this might change later.

I am wondering how the query then reads the cell: as a simple data (then it won't work, as in the first case), or as a string item, that is to say a line of code "to be inserted" into the code.

Is there any way to tell the query something like "you read the data in this cell and you insert it as a line of code"? ....

Thank you for your help.

Best regards,

G.
Aug 26 '07 #5
Scott Price
1,384 Expert 1GB
Hello,

I have tried as you said but it does not work either.

I feel that there is a problem of syntax in the code as when you build up the query in access, it puts by default an "=" into the code for the criteria field if nothing else is specified.

So my original query (the one that does not work) looks like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblProspects.CompName, tblProspects.Status
  2. FROM tblProspects
  3. WHERE (((tblProspects.Status)=DLookUp("[Statusrestrict]","Restrictions","[ID]=1")))
  4. GROUP BY tblProspects.CompName, tblProspects.Status;
In my table field [Statusrestrict], I have this data:

Expand|Select|Wrap|Line Numbers
  1. <>"AAA" And <>"BBB"
Then I have tried to put only one criteria in the field, that is to say that I tried with [Statusrestrict]=AAA and the code:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblProspects.CompName, tblProspects.Status
  2. FROM tblProspects
  3. WHERE (((tblProspects.Status)<>DLookUp("[Statusrestrict]","Restrictions","[ID]=1")))
  4. GROUP BY tblProspects.CompName, tblProspects.Status;
This actually is working very fine, but only with a single data to be filtered out. And in my case, I need to filter two or more data, without having to go through all the queries if this might change later.

I am wondering how the query then reads the cell: as a simple data (then it won't work, as in the first case), or as a string item, that is to say a line of code "to be inserted" into the code.

Is there any way to tell the query something like "you read the data in this cell and you insert it as a line of code"? ....

Thank you for your help.

Best regards,

G.

Access will read the data contained in your cell as a string. Try changing the criteria store in your cell to this: "AAA" And <>"BBB"
Use this with the second method that you have there... I.e. the <>DLookup() one.

Regards,
Scott
Aug 26 '07 #6

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

Similar topics

6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
2
by: Todd D. Levy | last post by:
I have a table of Country names & Country codes in alphabetical order. This is a lookup table that a number of other tables use to populate the Country field via a drop down Combo Box on the...
1
by: Steve | last post by:
I am using Access 2000 and I have a DB that is currently running four different queries from some Forms and subforms. These queries each have a date field that are seperate from each other that are...
1
by: max | last post by:
I have about 20 different querys but they all have some fields that use the same expression. I would like to add criteria to those fields without opening every query individually. Plus this...
21
by: Marc DVer | last post by:
I am trying to create a query that can be loaded as a querydef object but not having to assign values to the parameters if I don't want to. Normally when using a parameter query in VBA my code...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
1
by: Coll | last post by:
I have a database that produces different "cuts" of data for the user to export into excel. The database essentially opens queries using different criteria to filter the data as the user wants it....
5
by: Brett | last post by:
Hello, Is it possible to have just one criteria and have it apply to a group of queries? I am trying to create a report with the separate results of 4 queries based on a prompt for the user...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.