473,394 Members | 1,748 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.

Function In Query Criteria

I need help with a function to be used as the criteria for a query. The field in
the query is InventoryStatus:[Inventory] - [ReorderPoint]. The function is built
around a Select Case set of about twelve cases.

Function MyCriteria()
Select Case Forms!MyForm!MyCbx
Case 1
My Criteria = "<0"
Case 2
MyCriteria = "0"
Case 3
My Criteria = "Between 1 And 3"
Case 4
My Criteria = "Between 1 And 6"
etc
End Select
End Function

The above doesn't work!

Thanks for all help!

Steve
Nov 12 '05 #1
5 19297
On Mon, 29 Sep 2003 06:00:54 GMT in comp.databases.ms-access, "Steve"
<ss****@earthlink.net> wrote:
I need help with a function to be used as the criteria for a query. The field in
the query is InventoryStatus:[Inventory] - [ReorderPoint]. The function is built
around a Select Case set of about twelve cases.

Function MyCriteria()
Select Case Forms!MyForm!MyCbx
Case 1
My Criteria = "<0"
Case 2
MyCriteria = "0"
Case 3
My Criteria = "Between 1 And 3"
Case 4
My Criteria = "Between 1 And 6"
etc
End Select
End Function

The above doesn't work!


You might want to consider writing the entire SQL into the querydef
object and saving it each time if it's your goal to make the query
behave differently each time. If you're after opening a report with a
slightly different criteria then consider using the where clause
argument on the OpenReport method.

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #2
Hi,
Alternatively:

WHERE Choose( Forms!MyForm!MyCbx, (Inventory-ReorderPoint) <0,
(Inventory-ReorderPoint)=0, (Inventory-ReorderPoint) BETWEEN 1 and 3,
(Inventory-ReorderPoint) Between 1 and 6 )

Note that Choose is a function, not a statement, and thus, each of its
argument need to be evaluated.

Hoping it may help,
Vanderghast, Access MVP
"Trevor Best" <bouncer@localhost> wrote in message
news:0c********************************@4ax.com...
On Mon, 29 Sep 2003 06:00:54 GMT in comp.databases.ms-access, "Steve"
<ss****@earthlink.net> wrote:
I need help with a function to be used as the criteria for a query. The field inthe query is InventoryStatus:[Inventory] - [ReorderPoint]. The function is builtaround a Select Case set of about twelve cases.

Function MyCriteria()
Select Case Forms!MyForm!MyCbx
Case 1
My Criteria = "<0"
Case 2
MyCriteria = "0"
Case 3
My Criteria = "Between 1 And 3"
Case 4
My Criteria = "Between 1 And 6"
etc
End Select
End Function

The above doesn't work!


You might want to consider writing the entire SQL into the querydef
object and saving it each time if it's your goal to make the query
behave differently each time. If you're after opening a report with a
slightly different criteria then consider using the where clause
argument on the OpenReport method.

--
A)bort, R)etry, I)nfluence with large hammer.

Nov 12 '05 #3
"Steve" <ss****@earthlink.net> wrote in message news:<qU*******************@newsread2.news.atl.ear thlink.net>...
I need help with a function to be used as the criteria for a query. The field in
the query is InventoryStatus:[Inventory] - [ReorderPoint]. The function is built
around a Select Case set of about twelve cases.

Function MyCriteria()
Select Case Forms!MyForm!MyCbx
Case 1
My Criteria = "<0"
Case 2
MyCriteria = "0"
Case 3
My Criteria = "Between 1 And 3"
Case 4
My Criteria = "Between 1 And 6"
etc
End Select
End Function

The above doesn't work!

Thanks for all help!

Steve


For correctness (though not in this instance a dealbreaker) you should
declare the return type of the function e.g.

Function MyCriteria() As String

Otherwise, I can't see anything wrong. How does it "not work"?

Edward
Nov 12 '05 #4
On Mon, 29 Sep 2003 08:24:14 -0400 in comp.databases.ms-access,
"Michel Walsh" <va*********@msn.com> wrote:
Hi,
Alternatively:

WHERE Choose( Forms!MyForm!MyCbx, (Inventory-ReorderPoint) <0,
(Inventory-ReorderPoint)=0, (Inventory-ReorderPoint) BETWEEN 1 and 3,
(Inventory-ReorderPoint) Between 1 and 6 )

Note that Choose is a function, not a statement, and thus, each of its
argument need to be evaluated.


I'm not bothering to check there but are you sure? IIf() is a function
and when used in VBA all parameters are evaluated but if used in an
expression in a form or query it doesn't evaluate all parameters, it
works differently to VBA.

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #5
Hi
That is because there are two individuals sharing the same name, iif. In
Jet-SQL, iif is a statement, while in VBA, iif is a function. " If then
elseif else endIf ", in VBA is a (complex) statement. A statement is like a
control of the flow of execution. Not all parts of the control flow need to
be evaluated (like an unconditional GO TO that skips other statements and
functions ). A function, on the other hand, always evaluate its argument
even before beginning its own execution. As example, with

Abs( 4 + 5 )

the internal working of Abs will just see 9, not 4+5, and would not be able
to differentiate that 9 from another 9 coming from 12-3, as example. Abs( )
is a function. All the arguments are evaluated, then, the function is
called. You can trace that with

MyFunction3( MyFunction1() + MyFunction2( ) )

and you will see that MyFunction1 and MyFunction2 are called before
MyFunction3.

iif( ) - in VBA - is a function, so, each argument have to be evaluated
before iif starts. That is not a "special" rule, it is the general rules for
all functions.
iif( ) - in Jet SQL - is a statement, we cannot really speak of "argument"
here, but definitively, just the required "parts" are evaluated, as in any
other statements.
Choose( ) and Switch( ) are only defined in VBA, not in Jet SQL, and are
functions, not statements. As a side effect, you cannot use them from a C++
with Jet, or VB6 with Jet, just from a Access+Jet combo.

Hoping it may help,
Vanderghast, Access MVP

"Trevor Best" <bouncer@localhost> wrote in message
news:hf********************************@4ax.com...
On Mon, 29 Sep 2003 08:24:14 -0400 in comp.databases.ms-access,
"Michel Walsh" <va*********@msn.com> wrote:
Hi,
Alternatively:

WHERE Choose( Forms!MyForm!MyCbx, (Inventory-ReorderPoint) <0,
(Inventory-ReorderPoint)=0, (Inventory-ReorderPoint) BETWEEN 1 and 3,
(Inventory-ReorderPoint) Between 1 and 6 )

Note that Choose is a function, not a statement, and thus, each of itsargument need to be evaluated.


I'm not bothering to check there but are you sure? IIf() is a function
and when used in VBA all parameters are evaluated but if used in an
expression in a form or query it doesn't evaluate all parameters, it
works differently to VBA.

--
A)bort, R)etry, I)nfluence with large hammer.

Nov 12 '05 #6

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

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: stevecat | last post by:
Hi there, I have created a form, "search" and a query "search_product". The query returns the product information based upon the criteria for three of the fields, author, title or isbn. The field...
4
waynetheengineer
by: waynetheengineer | last post by:
Hi, I was wondering if anyone had any suggestions on my database: I have a form that accepts user input into a single text box. When the OK button is hit, a query should search for all records...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
6
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between...
3
by: sfrvn | last post by:
I have searched high and low and cannot find an answer to my problem. So now I turn to the collective genius of this newsgroup. Over-simplified examples This query criteria for field works:...
2
by: cmartin1986 | last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm. My problem today is I have a database that builds charts that are viewed by a large group every...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
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:
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: 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
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
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.