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

Is =GetMyCriteria() a valid criteria expression in query?

MLH
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 [DateLeft]. 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 -

Between #6/1/2005# And #6/30/2005#

I want to use them as criteria for the query.

There's a combo-box on the form whose row-source is the
above named query, qryVehiclesNowners2. How do I tell the
query that the criteria for that field is sitting in
Forms!MyForm!MyCrit waiting to be read 'n used?

I tried this on the criteria row in the QBE grid...
=[Forms]![frmLookUpAvehicle]![TimeCrit]

But I get a message saying "This expression is typed incorrectly,
or it is too complex to be evaluated. For example, a numeric ex-
pression may contain too many complicated elements. Try
simplifying the expression by assigning parts of the expression
to variables." The query runs fine if I delete only that field or
simply remove the reference criteria.

So I deleted the criteria, created a global var to hold the criteria
string value and a procedure in a standard module to return the
global var's value when called. Then I put the following criteria
in the query's [DateLeft] field:
=GetMyCriteria()
However, the query still pukes with the same error.

If I cut 'n paste the string from frmLookUpAvehicle's TimeCrit
textbox into the query, it runs as expected. So there's nothing
wrong with the syntax of the criteria string. Just seems it cannot
be referenced in the query - must be typed in there explicitly.

Someone know the answer?
Nov 13 '05 #1
3 3273
When you place the criteria the way you are doing it, the criteria isn't
being evaluated for what it says, it is being treated as a string. One way
around this is to modify the query using code.

Example:
Dim strSQL As String, strWhere As String
strSQL = "SELECT...." 'the part of the query that doesn't change
strWhere = Me!DateLeft
CurrentDb.QueryDefs("qryVehiclesNowners2").SQL = strSQL & " " & strWhere &
";"

--
Wayne Morgan
MS Access MVP
"MLH" <CR**@NorthState.net> wrote in message
news:5u********************************@4ax.com...
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 [DateLeft]. 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 -

Between #6/1/2005# And #6/30/2005#

I want to use them as criteria for the query.

There's a combo-box on the form whose row-source is the
above named query, qryVehiclesNowners2. How do I tell the
query that the criteria for that field is sitting in
Forms!MyForm!MyCrit waiting to be read 'n used?

I tried this on the criteria row in the QBE grid...
=[Forms]![frmLookUpAvehicle]![TimeCrit]

But I get a message saying "This expression is typed incorrectly,
or it is too complex to be evaluated. For example, a numeric ex-
pression may contain too many complicated elements. Try
simplifying the expression by assigning parts of the expression
to variables." The query runs fine if I delete only that field or
simply remove the reference criteria.

So I deleted the criteria, created a global var to hold the criteria
string value and a procedure in a standard module to return the
global var's value when called. Then I put the following criteria
in the query's [DateLeft] field:
=GetMyCriteria()
However, the query still pukes with the same error.

If I cut 'n paste the string from frmLookUpAvehicle's TimeCrit
textbox into the query, it runs as expected. So there's nothing
wrong with the syntax of the criteria string. Just seems it cannot
be referenced in the query - must be typed in there explicitly.

Someone know the answer?

Nov 13 '05 #2
MLH
Thank-you so much, Wayne, for your generous reply.
That's precisely what I had to do. I could not get past
the block I described. So, I recreated the entire query
in code, concatenating all the parts together and set
my combo-box's RowSource property to that after it
was properly constructed. Worked like a charm.

Thx again.
Nov 13 '05 #3
On Mon, 11 Jul 2005 18:36:46 -0400, MLH <CR**@NorthState.net> wrote:
Thank-you so much, Wayne, for your generous reply.
That's precisely what I had to do. I could not get past
the block I described. So, I recreated the entire query
in code, concatenating all the parts together and set
my combo-box's RowSource property to that after it
was properly constructed. Worked like a charm.

Thx again.

Hi
Honest but tactless if you do this too often!
It reads like "whenever I have a problem I post a question first and
then look for the answer"
David

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
3
by: Susan | last post by:
Can a textbox on a form be referenced as the criteria for a field in a crosstab query? When I use an expression like Forms!PFrmCriteria!Criteria, an error message appears saying Access can not...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
2
by: x | last post by:
hi i have made a crosstab query in which row heading is "date", colum heading is "aircraft type" and the value to be summed up is "1-10 row totals". i want to create a simple query which should...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
4
by: Tererai | last post by:
Hi guys? I am new to this community, i'm very pleased to join you. For the past 2 weeks i have been trying to specify criteria in a crosstab query but i get a fun message which says"Microsoft Jet...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
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...

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.