View Full Version : Queries and Confusion, Oh My!
gaving 05-23-2003, 06:35 AM Ok, this should be a breeze for most of you, but not for me.
Quick run down.
I have a new database that is using a form to enter in data, seven fields total. That's not the problem.
The problem is trying to run reports based on this data. Here are the fields:
Date
Shift: 1-3
Machine ID: 1-7
DownTime: Time/Hours
Component:
Lot:
Downtime Code: 30 codes
Comments:
I want to be able to enter in all this data and then run a report based on:
Date
Component
Downtime Code
However, the Date must be between two values at all times. The component, or the downtime code can be specified or left Null to pull all records.
But, the only one I can get to work is Component:
[Forms]![report]![txtComponent] Or [Forms]![report]![txtComponent] Is Null
What am I missing? If further details are needed please ask.
thanks,
Mile-O 05-23-2003, 06:38 AM Let's see your SQL as it is.
gaving 05-23-2003, 06:56 AM SELECT Downtime.Date, Downtime.Shift, Downtime.[Machine ID], Downtime.DownTime, Downtime.Lot, Downtime.Component, Downtime.[Down Code]
FROM Downtime
WHERE (((Downtime.Component)=[Forms]![report]![txtComponent]) AND ((Downtime.[Down Code])=[forms]![report]![cmbDowntimeCode])) OR ((([forms]![report]![cmbdowntimecode]) Is Null) AND (([forms]![report]![txtComponent]) Is Null));
Very bare, since I removed the Date selection. This is running off of a form (report).
Mile-O 05-23-2003, 07:06 AM Using the IsNull would only return the records where those fields don't have a value, but you want to return them all.
Try:
SELECT Downtime.Date, Downtime.Shift, Downtime.[Machine ID], Downtime.DownTime, Downtime.Lot, Downtime.Component, Downtime.[Down Code]
FROM Downtime
WHERE (((Downtime.Component)=[Forms]![report]![txtComponent]) AND ((Downtime.[Down Code])=[forms]![report]![cmbDowntimeCode])) OR ((([forms]![report]![cmbdowntimecode]) Like '*') AND (([forms]![report]![txtComponent]) Like '*'));
gaving 05-23-2003, 07:31 AM Hrmmmm. No dice.
I think it's due to my lack of explanation of what is needed though. If I find somewhere to upload screenshots I will since I couldn't explain how to get out of a paper bag right now (still half asleep).
thanks a ton Mile.
gaving 05-23-2003, 07:45 AM Going to give it one more shot since I'm desperate and Mile rocks.
Ok, data is entered into a table (downtime) via a form (entry). The users want to pull a report based on the data in the table (downtime) by using the form (report).
They want to query it by:
Date - Must have a beginning and ending date at all times
Component - an alpha numeric number, if field is empty, pull all records
Downtime Code - there are 30 codes, pull by code or if empty pull all codes.
Machine # - there are 7 machines
Scenario(s): I want to find all the 54400 Components between 01/01/2003 and 04/01/2003. So I would enter the beginning and ending date, and 54400 while leaving downtime code empty.
Or
I want to pull all the 001 Downtime Codes between 01/01/2003 and 04/01/2003.
Or
I want to pull all the 001 Downtime Codes with a Component of 54400 between 01/30/2003 and 2/15/2003.
Or
I want 002 Downtime Code, on Machine 4 with a component of 54400 between beginning date and ending date.
Or
Etc, etc, etc.
So, we go to the form (report) to enter our search criteria. Details of the form:
Beginning Date: txtBeginningDate
Ending Date: txtEndingDate
Downtime Code: cmbDowntimeCode
Machine #: txtMachine
Component: txtComponent
So will one query be able to pull all this data, or should it be broken up into multiple queries?
I think I explained it a bit better then... not sure.
Pat Hartman 05-24-2003, 11:21 AM SELECT Downtime.Date, Downtime.Shift, Downtime.[Machine ID], Downtime.DownTime, Downtime.Lot, Downtime.Component, Downtime.[Down Code]
FROM Downtime
WHERE (Downtime.Component = [Forms]![report]![txtComponent]) Or [forms]![report]![txtComponent]) Is Null) AND (Downtime.[Down Code] = [forms]![report]![cmbDowntimeCode] OR [forms]![report]![cmbdowntimecode] Is Null);
You did not have the clauses grouped properly. Basically you need the conditions to occur in a set enclosed within parentheses:
(fldA = formFldA Or formFldA Is Null) AND
(fldB = formFldB Or formFldB Is Null) AND
(fldC = formFldC Or formFldC Is Null)
|
|