Multiple Condition where Clause - Not working (1 Viewer)

Xproterg

Registered User.
Local time
Today, 11:59
Joined
Jan 20, 2011
Messages
67
Hey guys,

This is my first time posting in this particular section of the forums. I'm trying to work within an access database that has three text boxes and a listbox. The three textboxes contain dates. The contents of the listbox should be generated from the following query:

Code:
strSQL2 = "
 
SELECT Students_Info.firstname, Students_Info.lastname, Students_Info.cell 
 
FROM Students_Info 
 
WHERE ((Students_Info.gradONE BETWEEN 0 AND #" & checkdate2 & "#) and Students_Info.gradTWO='') OR 
 
((Students_Info.gradTWO BETWEEN 0 AND #" & checkdate2 & "#) and Students_Info.gradTHR='') 
 
OR (Students_Info.gradTHR BETWEEN 0 and #" & checkdate2 & "#);"

You can probably see what's going on in the code above. I'm working with three different conditions, each of which has two conditions.

Date One - The first condition is that Date One must be between 0 and today (which is checkdate2 variable). The second condition is that Date Two must be blank.

Date two goes along the same lines. The first condition is that Date Two must be between 0 and today (which is checkdate2 variable). The second condition is that Date Three must be blank.

Date Three is basically the same, but doesn't need the second condition as there is no Date 4 afterwards. The first condition is that Date Three must be between 0 and today (which is checkdate2 variable).


THE MAIN IDEA: The database handles students graduation dates. The students can take up to three classes in succession, each of which has a graduation date. The listbox needs to be populated with students that have graduated from their final course. The issue is that right now, with the code that i'm using that works, the list also populates with students that have another class coming up.

Anyways, I'm sure it's a simple fix, and I'd greatly appreciate any help anyone can toss in my direction. Thanks.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:59
Joined
Jan 20, 2009
Messages
12,859
Students_Info.gradTHR=''
This only finds the Null String where you probably want Null.

Try:
Students_Info.gradTHR Is Null

BTW. Three date fields used like that strongly suggests your data structure is not optimised.
 

Xproterg

Registered User.
Local time
Today, 11:59
Joined
Jan 20, 2011
Messages
67
It serves the purpose of automation. As far as I can comprehend, this is the only way to do it. I'll give your query a shot... thank you!

Update: Works like a charm. I really appreciate the help. Every bit of knowledge works wonders.
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:59
Joined
Jan 20, 2009
Messages
12,859
The difference between Null and "" pretty much catches everyone at least once.

The real gotcha is this one:

Code:
somefield <> "whatever"

Obviously Null is not equal to "whatever" but it won't find the Nulls.
You need:
Code:
somefield <> "whatever" OR somefield Is Null

Null simply does not compute with an equals oprator and even this expression returns False:
Null = Null
 

Users who are viewing this thread

Top Bottom