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

Query Criteria Help

I'm stuck. I use Access 2000. I have a date field in a query.
What I need done is if a Limit_Date function returns a true, I want
the date field to be Between 1/1/02 and 1/1/03, otherwise I want it
left alone(all records shown).

I have an if statement in the criteria:
iif(Limit_Date()=true,Between 1/1/02 and 1/1/03,"*")
This does not work since the if statement returns strings. So if
Limit_Date is true, then the criteria is "Between 1/1/02 and 1/1/03".
If its false then I get a *, which won't work with out a Like
statement.

Is there a way I can make a Between statement that accepts all dates?
I tried doing Between * and * but it does not work. I was hoping to
put if statements in the *, so if Limit_Date is true, the if would
return a date else "*".

Please help.

Thanks in advance.
Nov 13 '05 #1
2 4222
Where iif(limit_date()=true, date_field between #1/1/02# and #1/1/03#,
true)
Enterprise <va***@hotmail.com> posted in
news:e3**************************@posting.google.c om
I'm stuck. I use Access 2000. I have a date field in a query.
What I need done is if a Limit_Date function returns a true, I want
the date field to be Between 1/1/02 and 1/1/03, otherwise I want it
left alone(all records shown).

I have an if statement in the criteria:
iif(Limit_Date()=true,Between 1/1/02 and 1/1/03,"*")
This does not work since the if statement returns strings. So if
Limit_Date is true, then the criteria is "Between 1/1/02 and 1/1/03".
If its false then I get a *, which won't work with out a Like
statement.

Is there a way I can make a Between statement that accepts all dates?
I tried doing Between * and * but it does not work. I was hoping to
put if statements in the *, so if Limit_Date is true, the if would
return a date else "*".

Please help.

Thanks in advance.


--
Phil
Nov 13 '05 #2
Phil,

What you have is correct, but it must be typed into the SQL to work. If it
is typed into the criteria in the query design grid, Access will change it
to

WHERE Date_Field = IIf(....)

The problem with this is the IIf returns True or False, the date field will
be a date, not True or False, so the equation above is always False. If you
type what you have into the SQL then look at the design grid what you'll see
Access do with it is create a calculated field

Expr1:IIf(limit_date()=true, date_field between #1/1/02# and #1/1/03#, True)

with a criteria of

<>False

I don't know why it picks <>False instead of True, but either will work.
When you go back to the SQL, what you'll see is

WHERE IIf(limit_date()=true, date_field between #1/1/02# and #1/1/03#,
True)<>False

--
Wayne Morgan
Microsoft Access MVP
"Phil" <st***@basketball.net> wrote in message
news:82*****************@newssvr22.news.prodigy.co m...
Where iif(limit_date()=true, date_field between #1/1/02# and #1/1/03#,
true)
Enterprise <va***@hotmail.com> posted in
news:e3**************************@posting.google.c om
I'm stuck. I use Access 2000. I have a date field in a query.
What I need done is if a Limit_Date function returns a true, I want
the date field to be Between 1/1/02 and 1/1/03, otherwise I want it
left alone(all records shown).

I have an if statement in the criteria:
iif(Limit_Date()=true,Between 1/1/02 and 1/1/03,"*")
This does not work since the if statement returns strings. So if
Limit_Date is true, then the criteria is "Between 1/1/02 and 1/1/03".
If its false then I get a *, which won't work with out a Like
statement.

Is there a way I can make a Between statement that accepts all dates?
I tried doing Between * and * but it does not work. I was hoping to
put if statements in the *, so if Limit_Date is true, the if would
return a date else "*".

Please help.

Thanks in advance.


--
Phil

Nov 13 '05 #3

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

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
3
by: dskillingstad | last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong, but.... I've searched these groups for some solutions but no luck. I have an unbound form (frmSearch), with several unbound...
1
by: S. van Beek | last post by:
Dear reader, How can I filter a numeric field with Like as criteria in a query. To filter a numeric field with <10 as criteria this will com back with the result of those records for which...
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...
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...
4
by: dizzydangler | last post by:
Hi all, I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.