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

Using IIf in Criteria for a query

I have a query with a numeric field called BALBOOK. I have a form
(we'll call it Form1) that runs this query. On this form is a text
box (we'll call it Text1). When the query is run, I want is to use
all the records from a file where BALBOOK is equal to Text1. However,
if Text1 is blank (or null) I want the query to use all the records.

I don't know how to write the IIf statement. It would look something
like this:

IIf(Isnumeric([Forms].[Form1].[Text1]),CInt(([Forms].[Form1].[Text1])),"???")

The "???" is where I am stuck. I have tried ">0" (without the
quotes). I have tried leaving it blank. It works of Text1 is
numeric. It does not work if it is left blank.

Any suggestions?
Nov 13 '05 #1
4 2556
pw****@hotmail.com (Paul) wrote:
IIf(Isnumeric([Forms].[Form1].[Text1]),CInt(([Forms].[Form1].[Text1])),"
???")


Try this (untested):

IIf(Not IsNull([Forms]![Form1]![Text1]),CInt([Forms]![Form1]![Text1]),Null)

If there's something in the text box it will be used as the criteria. If
the text box is null then so will the criteria.

Regards,
Keith.
Nov 13 '05 #2
Paul wrote:
I have a query with a numeric field called BALBOOK. I have a form
(we'll call it Form1) that runs this query. On this form is a text
box (we'll call it Text1). When the query is run, I want is to use
all the records from a file where BALBOOK is equal to Text1. However,
if Text1 is blank (or null) I want the query to use all the records.

I don't know how to write the IIf statement. It would look something
like this:

IIf(Isnumeric([Forms].[Form1].[Text1]),CInt(([Forms].[Form1].[Text1])),"???")

The "???" is where I am stuck. I have tried ">0" (without the
quotes). I have tried leaving it blank. It works of Text1 is
numeric. It does not work if it is left blank.

Any suggestions?


Hae a look at

http://www.mvps.org/access/queries/qry0001.htm


Nov 13 '05 #3
Keith Wilby <ke*********@AwayWithYerCrap.com> wrote in message news:<Xn***********************@10.15.188.42>...
pw****@hotmail.com (Paul) wrote:
IIf(Isnumeric([Forms].[Form1].[Text1]),CInt(([Forms].[Form1].[Text1])),"
???")


Try this (untested):

IIf(Not IsNull([Forms]![Form1]![Text1]),CInt([Forms]![Form1]![Text1]),Null)

If there's something in the text box it will be used as the criteria. If
the text box is null then so will the criteria.


Maybe I'm a little confused, but I'm thinking that if this works at
all it will at best limit your results to those records where this
field is Null rather than applying no criterion to this field at all.

In situations like this I usually build an SQL string in the form
itself and then run it or, if you need compiled query performance,
just build two separate queries, one with the criterion based on the
text box defined, and one without.

Bruce
Nov 13 '05 #4
br***@aristotle.net (Bruce) wrote:
I'm thinking that if this works at
all it will at best limit your results to those records where this
field is Null rather than applying no criterion to this field at all.


I would have thought that to return null instances, the 'false' part would
have to read "Is Null". Isn't by having just 'Null' in there the same as
not entering any criteria, ie leave it null?
Nov 13 '05 #5

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

Similar topics

4
by: nick_faye | last post by:
hi, hope someone can help me. i am a newbie in creating queries and i want to create a query wherein i only get entries from my table where values of fields 2, 3 and 4 are not zeros. for...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
3
by: pelcovits | last post by:
I am trying to set up an unbound form to enter report criteria. I've followed the MS Office Assistance document: "Create a form to enter report criteria" which describes how to enter data (such...
0
by: MLH | last post by:
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...
3
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...
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...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
1
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
13
by: Robertf987 | last post by:
Hi, Yet another thing I need help with I'm affraid. I'll first explain what I want, then I'll try to explain what I have. I'm using Microsoft Access 2000. What I want is to be able to do a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.