In Access 2003 I have a query where it asks the user for two parameter using [Enter Emp #] and [Enter Task Type] pop up. However, I need for the query to return all tasks for the Emp# if TaskType is left blank. I tried "In" in the or section of the query, but that returned all records for all emp#s....unless I used incorrectly.
Thxs for help.
23 1661
Try something like this. -
SELECT * FROM TableName
-
WHERE ([Emp#] = [Enter Emp #]
-
AND [Task Type] = nz([Enter Task Type],"*")
-
Mary
Try something like this. -
SELECT * FROM TableName
-
WHERE ([Emp#] = [Enter Emp #]
-
AND [Task Type] = nz([Enter Task Type],"*")
-
Mary
Thank you Mary, will give it a shot.
NeoPa 32,556
Expert Mod 16PB
Neat idea but I'd use the LIKE in place of the '='. - SELECT * FROM TableName
-
WHERE ([Emp#]=[Enter Emp #])
-
AND ([Task Type] Like Nz([Enter Task Type],'*')
Neat idea but I'd use the LIKE in place of the '='. - SELECT * FROM TableName
-
WHERE ([Emp#]=[Enter Emp #])
-
AND ([Task Type] Like Nz([Enter Task Type],'*')
Okay, that worked.
And you guys are going to kill me. Lets say I wanted to filter out certain task types when the field is left blank. The tasks I am interested in tracking are PT, ET, UT. So, with the this code the user can either input ET in [Enter Task Type] or leave bank and the code returns all task types for the user. That is good, but what would be perfect if it only returned ET, PT, UT for the user if [Enter Task Type] is left blank. I know I did not have this in my original question, but at the time it did not dawn on me.
Thank you for any extra help, you guys have been great.
NeoPa 32,556
Expert Mod 16PB
This gets a little more oblique, but can be done. Try : - SELECT *
-
FROM [TableName]
-
WHERE ([Emp#]=[Enter Emp #])
-
AND IIf(IsNull([Enter Task Type]),
-
[Task Type] In('ET','PT','UT'),
-
[Task Type]=[Enter Task Type])
This one you owe me a pint for :D
BTW I tested the concept and it worked perfectly.
This gets a little more oblique, but can be done. Try : - SELECT *
-
FROM [TableName]
-
WHERE ([Emp#]=[Enter Emp #])
-
AND IIf(IsNull([Enter Task Type]),
-
[Task Type] In('ET','PT','UT'),
-
[Task Type]=[Enter Task Type])
This one you owe me a pint for :D
BTW I tested the concept and it worked perfectly.
Nice solution Ade!
Well Neo, where can I send that pint?
Worked like a champ.
One more question :).
Is this coding something that can be learned by book or some sort of intermediate course on Access? Or is it code that one would have to take VBA courses to learn?
Just looking ahead.
Well Neo, where can I send that pint?
Worked like a champ.
One more question :).
Is this coding something that can be learned by book or some sort of intermediate course on Access? Or is it code that one would have to take VBA courses to learn?
Just looking ahead.
This is actually a combination of SQL code and Access functions. It is pretty standard as far as the SQL is concerned and the IIf function is a commonly used Access function.
The Access help file is a good place to learn about Access functions. SQL is a little more complicated.
NeoPa 32,556
Expert Mod 16PB
Well Neo, where can I send that pint?
Worked like a champ.
One more question :).
Is this coding something that can be learned by book or some sort of intermediate course on Access? Or is it code that one would have to take VBA courses to learn?
Just looking ahead.
Mary just beat me into this one. I thought I'd get home before answering properly ;)
Actually the Access Help file also has a full set of help for Access SQL if you can find it.
Really, the SQL I posted was just basic stuff. It was the concept that is a bit out of the ordinary. I simply used the IIf() function to return boolean values rather than numeric or string values which are more commonly used. That is just an experience thing really, and a willingness to look for the less obvious solutions sometimes.
In this case (where IIf() is used within a SQL string), the IIf() function is actually SQL code rather than VBA. It has an important difference from the VBA version, which is that it will only evaluate the required leg of the function.
Okay,
I tried the same code on another application where if user enters [Enter Emp #] and if [Enter Date dd/mm/yy] is left blank, displays records with current date.
This is what I did: - WHERE ([emp#]=[Enter Emp #])
-
AND Like Nz([Enter Date dd/mm/yy],'Date()')
So, that returns current date in report but no records are returned for employee or anyone else.
Obviously I did not do it right, so where did I miss the boat?
Okay,
I tried the same code on another application where if user enters [Enter Emp #] and if [Enter Date dd/mm/yy] is left blank, displays records with current date.
This is what I did: - WHERE ([emp#]=[Enter Emp #])
-
AND Like Nz([Enter Date dd/mm/yy],'Date()')
So, that returns current date in report but no records are returned for employee or anyone else.
Obviously I did not do it right, so where did I miss the boat?
Remove the single quotes from around Date(). It's a function, not a string.
Otherwise, very good attempt.
Remove the single quotes from around Date(). It's a function, not a string.
Otherwise, very good attempt.
Tried that, getting syntax error. Here is actuial snippet of code from teh query: - Where (((QryjoinCompjobswithempquery.[Employee #])=[Enter Emp #] AND ((tblJobsComp.[Created Date Local])=Nz[Enter Date mm/dd/yy], Date()));
Where is the syntax error?
-
Where (((QryjoinCompjobswithempquery.[Employee #])=[Enter Emp #])
-
AND ((tblJobsComp.[Created Date Local])=Nz([Enter Date mm/dd/yy], Date())));
-
You didn't have an opening bracket after nz. Try the above.
Mary
-
Where (((QryjoinCompjobswithempquery.[Employee #])=[Enter Emp #])
-
AND ((tblJobsComp.[Created Date Local])=Nz([Enter Date mm/dd/yy], Date())));
-
You didn't have an opening bracket after nz. Try the above.
Mary
Ding!
Thank you very much.
Great stuff, if it is any consolation I am off for the rest of the week, so I wont pester you guys any more...until then :).
Ding!
Thank you very much.
Great stuff, if it is any consolation I am off for the rest of the week, so I wont pester you guys any more...until then :).
No problem. Glad you've got it working.
Mary
NeoPa 32,556
Expert Mod 16PB
Ding!
Thank you very much.
Great stuff, if it is any consolation I am off for the rest of the week, so I wont pester you guys any more...until then :).
Until then, then :) (What did I just let myself in for :D)
Until then, then :) (What did I just let myself in for :D)
Hiya Neo,
One more question on this subject. I would like to take this code a little bit further and maybe you or mccarthy can tell me how I can make this work if possible: - WHERE (((tblEmployees.[Employee Number])=[Enter Emp #])
-
And IIf(IsNull([Enter Task Type]),[Task Type] In ('Borescope','ET','PT','UT','RT'),[Task Type]=[Enter Task Type])
-
And ((tblAcftJobsComp.[Created Date Local])>=[From Dte mm/dd/yy]));
To the above code I would like to add - =Nz([Enter Date mm/dd/yy], DateAdd("d", 30, Now))))
I am not sure how to work it in with the >= comparison operator. I am asking the user from what date he wants to display the records. However, based on previous ideas, if he leaves the field blank, I would like the query to return the past 30 days.
NeoPa 32,556
Expert Mod 16PB
I can't get to this now as it's been hectic all day.
It looks like you're on the right lines - I'll have a look later at finalising the details for you :)
NeoPa 32,556
Expert Mod 16PB
Try using : - ...>Nz([Enter Date mm/dd/yy], DateAdd("d", -30, Date()))
Let me know if that works. If not then post your current SQL code but try to lay it out so that I can read it without copying it to a text-editor first.
Try using : - ...>Nz([Enter Date mm/dd/yy], DateAdd("d", -30, Date()))
Let me know if that works. If not then post your current SQL code but try to lay it out so that I can read it without copying it to a text-editor first.
Good Morning Neopa,
I tried the above and I am getting a syntax error. Here is the SQL: -
And ((tblAcftJobsComp.[Created Date Local])
-
>Nz([Enter Date mm/dd/yy], DateAdd("d", -30, Date()));
-
Hope I layed it out okay for ya, wasnt sure what you meant, so I assumed to mean to break it up in the window.
NeoPa 32,556
Expert Mod 16PB
It's hard without the full SQL (Well laid out by the way - perfectly readable), but immediately obvious is that you've introduced an unclosed opening parenthesis '('. Try balancing them all up properly first, then, if that won't work, post the full SQL & I'll check it for you. If there's anything more to the error message that would be helpful too.
It's hard without the full SQL (Well laid out by the way - perfectly readable), but immediately obvious is that you've introduced an unclosed opening parenthesis '('. Try balancing them all up properly first, then, if that won't work, post the full SQL & I'll check it for you. If there's anything more to the error message that would be helpful too.
Okay, parenthesis fixed. Thxs.
Now to deal with that other thread :). I am going to address the field naming issue foist, then get back to you with the rest.
NeoPa 32,556
Expert Mod 16PB
Sounds fine.
Well done for fixing the parentheses :) Glad to hear it fixed the problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Greg Strong |
last post by:
Hello All,
In the past I've used a combo box with the 'row source' being an Access SQL
union query to select "All" or 1 for only 1 criteria in a query. An example
is as follows:
SELECT 0 As...
|
by: Julio Allegue |
last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It
returns all the rows. It doesn't seem to look at the WHERE clause. At
the same time, I am getting the correct count on "SQL...
|
by: comp.lang.php |
last post by:
$orderBy = 's.app_date desc, s.last_name asc, s.first_name asc, s.mi
asc';
if ($_REQUEST) {
$ascArray = array('asc' => 'desc', 'desc' => 'asc'); // ARRAY OF
ALL ORDERING POSSIBILITIES
$junk =...
|
by: jht5945 |
last post by:
For example I wrote a function:
function Func()
{
// do something
}
we can call it like:
var obj = new Func(); // call it as a constructor
or
var result = Func(); // call it as...
|
by: Johs |
last post by:
When I declare a string in C++ I type:
std::string mystring = "sdfsdf";
afterwards I can access string methods like:
mystring.
but why is there both :: and . operators and what are the...
|
by: lsllcm |
last post by:
Hi All,
I have one question about many "or" operation make system choose
incorrect index
There is one table TT (
C1 VARCHAR(15) NOT NULL,
C2 VARCHAR(15) NOT NULL,
C3 VARCHAR(15) NOT NULL,...
|
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...
|
by: kpfunf |
last post by:
I have a select query that uses an "OR" join. With that join in place, I cannot edit the data in the query datasheet; if I delete the "OR" and only use one join, then I can edit the data. I read...
|
by: jonceramic |
last post by:
Hi All,
My apologies for asking something that I'm sure has been answered
for. But, my google searching can't find a proper set of keywords.
I would like to add "New..." or "other..." or...
|
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
|
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...
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |