473,795 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difficult SQL Query

I've written a Query that gets info from an Option Group and some combo
boxes that returns the correct data if,in the last "AND" of the "WHERE"
I compare [AI Detail].[Assignee Short] to "RS"
When I try to compare [AI Detail].[Assignee Short] to [Forms]![Action
Item Review]![cboAssignee], a combo box populated with RS it returns
nothing. I would think that both of the following queries would be
equal. Where is my logic failing?

I've looked at this for 2 days and either haven't found a reference to
the problem or didn't recognize it when I saw it.

*************** *************** *************** *************** ***********
SQL with "RS"
*************** *************** *************** *************** ***********
SELECT DISTINCT [AI Master].[AI Key], [AI Master].[Assign Date], [AI
Master].[Expected Date], [AI Master].CompleteDate, [AI Master].[AI Title]
FROM [AI Master] INNER JOIN [AI Detail] ON [AI Master].[AI Key] = [AI
Detail].[AI Key]
WHERE ((([AI Master].[Expected Date]) Between [Forms]![Action Item
Review]![S] And [Forms]![Action Item Review]![E]) AND
((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item
Review]![AIStatusOptions]=3,[CompleteDate] Is Not Null,[AI Master]![AI
Key] Is Not Null))))<>False ) AND (([AI Detail].[Assignee Short])="RS"))
ORDER BY [AI Master].[AI Key] DESC;

*************** *************** *************** *************** **********
SQL that references the Combo Box containing RS
*************** *************** *************** *************** ***********
SELECT DISTINCT [AI Master].[AI Key], [AI Master].[Assign Date], [AI
Master].[Expected Date], [AI Master].CompleteDate, [AI Master].[AI Title]
FROM [AI Master] INNER JOIN [AI Detail] ON [AI Master].[AI Key] = [AI
Detail].[AI Key]
WHERE ((([AI Master].[Expected Date]) Between [Forms]![Action Item
Review]![S] And [Forms]![Action Item Review]![E]) AND
((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item
Review]![AIStatusOptions]=3,[CompleteDate] Is Not Null,[AI Master]![AI
Key] Is Not Null))))<>False ) AND (([AI Detail].[Assignee
Short])=[Forms]![Action Item Review]![cboAssignee]))
ORDER BY [AI Master].[AI Key] DESC;
I'm a Newbie! If there's a better mousetrap I'll stick my fingers in it!
Thanks in advance.
Nov 13 '05 #1
3 1421
You can't do things like

((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item Review]![AIStatusOptions]=3,[CompleteDate] Is
Not Null,[AI Master]![AI Key] Is Not Null))))<>False )

in SQL. An IIf statement can only return a value: it can't return a phrase
that's supposed to be part of the SQL statement.

You'll need to use something like:

(([Forms]![Action Item Review]![AIStatusOptions]=2 AND [CompleteDate] Is
Null)
OR ([Forms]![Action Item Review]![AIStatusOptions]=3 AND [CompleteDate] Is
Not Null)
OR ([Forms]![Action Item Review]![AIStatusOptions] NOT IN (2, 3) AND [AI
Master]![AI Key] Is Not Null))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Chris Belcher" <ch******@bells outh.net> wrote in message
news:IT******** ***********@big news3.bellsouth .net...
I've written a Query that gets info from an Option Group and some combo
boxes that returns the correct data if,in the last "AND" of the "WHERE"
I compare [AI Detail].[Assignee Short] to "RS"
When I try to compare [AI Detail].[Assignee Short] to [Forms]![Action
Item Review]![cboAssignee], a combo box populated with RS it returns
nothing. I would think that both of the following queries would be
equal. Where is my logic failing?

I've looked at this for 2 days and either haven't found a reference to
the problem or didn't recognize it when I saw it.

*************** *************** *************** *************** ***********
SQL with "RS"
*************** *************** *************** *************** ***********
SELECT DISTINCT [AI Master].[AI Key], [AI Master].[Assign Date], [AI
Master].[Expected Date], [AI Master].CompleteDate, [AI Master].[AI Title]
FROM [AI Master] INNER JOIN [AI Detail] ON [AI Master].[AI Key] = [AI
Detail].[AI Key]
WHERE ((([AI Master].[Expected Date]) Between [Forms]![Action Item
Review]![S] And [Forms]![Action Item Review]![E]) AND
((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item
Review]![AIStatusOptions]=3,[CompleteDate] Is Not Null,[AI Master]![AI
Key] Is Not Null))))<>False ) AND (([AI Detail].[Assignee Short])="RS"))
ORDER BY [AI Master].[AI Key] DESC;

*************** *************** *************** *************** **********
SQL that references the Combo Box containing RS
*************** *************** *************** *************** ***********
SELECT DISTINCT [AI Master].[AI Key], [AI Master].[Assign Date], [AI
Master].[Expected Date], [AI Master].CompleteDate, [AI Master].[AI Title]
FROM [AI Master] INNER JOIN [AI Detail] ON [AI Master].[AI Key] = [AI
Detail].[AI Key]
WHERE ((([AI Master].[Expected Date]) Between [Forms]![Action Item
Review]![S] And [Forms]![Action Item Review]![E]) AND
((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item
Review]![AIStatusOptions]=3,[CompleteDate] Is Not Null,[AI Master]![AI
Key] Is Not Null))))<>False ) AND (([AI Detail].[Assignee
Short])=[Forms]![Action Item Review]![cboAssignee]))
ORDER BY [AI Master].[AI Key] DESC;
I'm a Newbie! If there's a better mousetrap I'll stick my fingers in it!
Thanks in advance.

Nov 13 '05 #2
Thanks Doug. Actually the IIf's evaluated correctly (Now I don't really
know why other than I'm checking for the existance of a date entry. but
I'm still stumped... Let me simplify it for another shot at the question.

SELECT [AI Detail].[AI Key], [AI Detail].[Assignee Short]
FROM [AI Detail]
WHERE [AI Detail].[Assignee Short]=[Forms]![Action Item
Review]![cbxAssignee];

Does not evaluate to the same results as even though the combo box
contains JV

SELECT [AI Detail].[AI Key], [AI Detail].[Assignee Short]
FROM [AI Detail]
WHERE [AI Detail].[Assignee Short]= "JV";


Douglas J. Steele wrote:
You can't do things like

((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item Review]![AIStatusOptions]=3,[CompleteDate] Is
Not Null,[AI Master]![AI Key] Is Not Null))))<>False )

in SQL. An IIf statement can only return a value: it can't return a phrase
that's supposed to be part of the SQL statement.

You'll need to use something like:

(([Forms]![Action Item Review]![AIStatusOptions]=2 AND [CompleteDate] Is
Null)
OR ([Forms]![Action Item Review]![AIStatusOptions]=3 AND [CompleteDate] Is
Not Null)
OR ([Forms]![Action Item Review]![AIStatusOptions] NOT IN (2, 3) AND [AI
Master]![AI Key] Is Not Null))

Nov 13 '05 #3
You sure the combo box contains JV, and not, say "JV " or " JV "?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Chris Belcher" <ch******@bells outh.net> wrote in message
news:GU******** **********@bign ews6.bellsouth. net...
Thanks Doug. Actually the IIf's evaluated correctly (Now I don't really
know why other than I'm checking for the existance of a date entry. but
I'm still stumped... Let me simplify it for another shot at the question.

SELECT [AI Detail].[AI Key], [AI Detail].[Assignee Short]
FROM [AI Detail]
WHERE [AI Detail].[Assignee Short]=[Forms]![Action Item
Review]![cbxAssignee];

Does not evaluate to the same results as even though the combo box
contains JV

SELECT [AI Detail].[AI Key], [AI Detail].[Assignee Short]
FROM [AI Detail]
WHERE [AI Detail].[Assignee Short]= "JV";


Douglas J. Steele wrote:
You can't do things like

((IIf([Forms]![Action Item Review]![AIStatusOptions]=2,[CompleteDate] Is
Null,(IIf([Forms]![Action Item Review]![AIStatusOptions]=3,[CompleteDate] Is Not Null,[AI Master]![AI Key] Is Not Null))))<>False )

in SQL. An IIf statement can only return a value: it can't return a phrase that's supposed to be part of the SQL statement.

You'll need to use something like:

(([Forms]![Action Item Review]![AIStatusOptions]=2 AND [CompleteDate] Is
Null)
OR ([Forms]![Action Item Review]![AIStatusOptions]=3 AND [CompleteDate] Is Not Null)
OR ([Forms]![Action Item Review]![AIStatusOptions] NOT IN (2, 3) AND [AI
Master]![AI Key] Is Not Null))

Nov 13 '05 #4

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

Similar topics

7
2826
by: M Wells | last post by:
Hi All, I have what seems to me to be a difficult query request for a database I've inherited. I have a table that has a varchar(2000) column that is used to store system and user messages from an on-line ordering system. For some reason (I have no idea why), when the original database was being designed no thought was given to putting these messages in
5
1477
by: Bob | last post by:
Hi Everybody Difficult question Has anyone else used the "Using the Tab control as a container" database example that comes with the above book chapter 7 on the accompanying disc. It is a brilliant piece of design that I have used in 2 previous projects and they have worked beautifully. What it does is set up the tabs in a container with a different tab
4
2074
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating premiums are dependant on the country in which the client is in. Therefore, we have a Country table, with its list of rates, a client table and then the property table. Getting this is great, works fine, easy! Problem is, now I need to work out a...
5
1805
by: jmartineau | last post by:
Hello, Here is a brief summary: Table 1 = All Accounts - with fields such as Customer ID and Account # Table 2 = Deposit Balance Table - with fields such as Account #, Balance
4
2025
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class, a random number of students arrive, each of which has completed a random number of lessons taken at random from the curriculum.
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.