Hi Ken,
I have the query working like it should. But now I am getting results as if
I used the word "LIKE" as I had initially. I changed it a while ago and it is
still acting as if I have it in there. Here is my updated version of the
query:
SELECT tblResults.Q_INC, tblResults.SAMPLE_NO, tblResults.TENSION,
tblResults.NOTES, tblResults.OBSERVATIONS, tblResults.L_PART_NO,
tblResults.K_PART_NO, tblResults.PAT_NO, tblResults.PAT_SIZE
FROM tblResults
WHERE ((tblResults.L_ID)
In (select L_ID from tblLock
Where (L_EWO_NO = '[forms].[frmCustomResultReport].[cmbLEWO]' OR
[forms].[frmCustomResultReport].[cmbLEWO] = "<all>") AND (L_PART_NO =
'[forms].[frmCustomResultReport].[cmbLPart]' OR
[forms].[frmCustomResultReport].[cmbLPart] = "<all>") AND (L_SKID_NO =
'[forms].[frmCustomResultReport].[cmbLSKID]' OR
[forms].[frmCustomResultReport].[cmbLSKID] = "<all>") AND (L_MAT_TYPE =
'[forms].[frmCustomResultReport].[cmbLMatType]' OR
[forms].[frmCustomResultReport].[cmbLMatType] = "<all>") AND (L_MAT_HEAT =
'[forms].[frmCustomResultReport].[cmbLMatHeat]' OR
[forms].[frmCustomResultReport].[cmbLMatHeat] = "<all>") AND (L_HARD =
'[forms].[frmCustomResultReport].[cmbLHard]' OR
[forms].[frmCustomResultReport].[cmbLHard] = "<all>") AND (L_PLAT =
'[forms].[frmCustomResultReport].[cmbLPlat]' OR
[forms].[frmCustomResultReport].[cmbLPlat] = "<all>") AND (L_TOP_COAT =
'[forms].[frmCustomResultReport].[cmbLCoat]' OR
[forms].[frmCustomResultReport].[cmbLCoat] = "<all>") AND (L_THREAD =
'[forms].[frmCustomResultReport].[cmbLThread]' OR
[forms].[frmCustomResultReport].[cmbLThread] = "<all>") )
AND (tblResults.K_ID) IN (Select K_ID from tblKey Where( K_EWO_NO =
'[forms].[frmCustomResultReport].[cmbKEWO]' OR
[forms].[frmCustomResultReport].[cmbKEWO] = "<all>") AND (K_PART_NO =
'[forms].[frmCustomResultReport].[cmbKPart]' OR
[forms].[frmCustomResultReport].[cmbKPart] = "<all>") AND (K_SKID_NO =
'[forms].[frmCustomResultReport].[cmbKSKID]' OR
[forms].[frmCustomResultReport].[cmbKSKID] = "<all>") AND (K_MAT_TYPE =
'[forms].[frmCustomResultReport].[cmbKMatType]' OR
[forms].[frmCustomResultReport].[cmbKMatType] = "<all>") AND (K_MAT_HEAT =
'[forms].[frmCustomResultReport].[cmbKMatHeat]' OR
[forms].[frmCustomResultReport].[cmbKMatHeat] = "<all>") AND (K_HARD =
'[forms].[frmCustomResultReport].[cmbKHard]' OR
[forms].[frmCustomResultReport].[cmbKHard] = "<all>") AND (K_PLAT =
'[forms].[frmCustomResultReport].[cmbKPlat]' OR
[forms].[frmCustomResultReport].[cmbKPlat] = "<all>") AND (K_TOP_COAT =
'[forms].[frmCustomResultReport].[cmbKCoat]' OR
[forms].[frmCustomResultReport].[cmbKCoat] = "<all>") ) );
If I say show all results where L_MAT_TYPE = 5, I get results where the
L_MAT_TYPE = 56...
I tried doing the null thing, but I didn't understand it much, but what I
have seems to work. Please let me know what you think i should do. Thank you!
~Erica~
Ken Sheridan said:
Erica:
Let's hope so, but if you do need any further help post back.
Ken Sheridan
Stafford, England
:
Now that I think about it, I think I still may need to track the lock by the
L_ID...
If I say where L_ID in (Select L_ID where .....) then I will get each L_ID
where L_PART_NO = this and/or L_MAT_Heat = that. Then the out put would be
each result using a L_ID listed in the query's results.
Maybe I just solved it myself, we'll see...lol
:
Ken,
I rearranged the query to how you wrote it and I think it might have done
the same thing as what I ended up with yesterday using the iif statement
(this was is simpler though).
I Believe the query works the way it is written to, however it's still not
producing the results i need. Let me explain tblLock:
table lock consists of L_ID (PK) that is an AutoNumber field. so there may
be times where you will have the same L_PART_NO, but different variations of
it, hence the need for L_ID.
In my results table I wanted to track which lock they were using, but I
tracked it by the L_PART_NO instead of L_ID because the users want to see
this information.
I am trying to establish a way to track the results that have a L_PART_NO of
this or a MAT_HEAT of that. It may not be necessary to have L_PART_NO in the
results table, but I do not know how to link these two tables together
because the are not directly connected in table relationships for other
reasons.
Basically, I am just trying to find the record(s) in the lock table that
match the values selected by the user in the combo boxes if that makes any
sense. so if a person select a value only for MAT_HEAT, I want to see all
results where the Lock Part Number's MAT_HEAT value matches whatever they
selected no matter what the lock part number is.
I hope this make sense... My table relationships must stay the way they are.
Everything flows the way it's supposed to, so I do see the need in changing
it. I just need to figure out how to do some complex reporting. I do not have
a big backgroud with it.
Let me know if you have any other suggestions, thank you!
~Erica~
:
Erica:
You need to evaluate whether the relevant column in the table matches the
value in the combo box, OR the combo box = "<All>". Consequently each of
these Boolean OR operations will evaluate to TRUE for rows where there is a
match for a selected value, or for every row in the case of the combo box's
value being the default <All> .
Each OR operation is parenthesised to force it to evaluate independently and
they are all tacked together in Boolean AND operations. Rows will only be
returned therefore where every parenthesised expression evaluates to TRUE for
that row.
So the WHERE condition goes like this:
WHERE (L_EWO_NO = [forms].[frmCustomResultReport].[cmbLEWO]
OR [forms].[frmCustomResultReport].[cmbLEWO] = "<All>")
AND (L_PART_NO = [forms].[frmCustomResultReport].[cmbLPart]
OR [forms].[frmCustomResultReport].[cmbLPart] = "<All>")
< and so on to>
AND (L_THREAD = [forms].[frmCustomResultReport].[cmbLThread]
OR [forms].[frmCustomResultReport].[cmbLThread] = "<All>")
NB: only use the LIKE operator if you are matching partial values, in which
case you'd incorporate wildcard characters, otherwise use the normal equality
operator (the equals sign). If you want selecting 'Smith' to return 'Smith',
'Smithson', 'Smithereen', 'Arrowsmith' etc then use LastName LIKE "*" &
cboLastName & "*", but to simply return 'Smith' use LastName = cboLastName.
The SQL above assumes that <All> is in the bound columns of the combo boxes'
RowSources in each case, and not in a visible column corresponding to a
hidden bound column (e.g. cases such as where a numeric EmployeeID is in a
hidden bound column but FirstName & " " & LastName is in the visible column).
In such circumstances I'd usually leave the bound column for <All> Null, in
which case rather than = "<All>" I'd use IS NULL (do not use '= NULL' note;
nothing equals NULL, not even another NULL).
Ken Sheridan
Stafford, England
:
Hello,
I am trying to create a query that will take values from a form consisting
of several combo boxes as its criteria.
What I want to do is show all records that meet the criteria that was
selected. For instance; if you have a form that consists of cmbA, cmbB and
cmbC and you choose a value in cmbA & cmbB only the query will return results
that match
cmbA AND cmbB.
right now, the query returns results that match every cmbo box value even if
the user chose <all> (the default value) I've tried using OR but that is not
what I want to use either.
I am wondering if this can even be done... Here is my code for the query:
SELECT tblResults.Q_INC, tblResults.SAMPLE_NO, tblResults.TENSION,
tblResults.NOTES, tblResults.OBSERVATIONS, tblResults.L_PART_NO,
tblResults.K_PART_NO, tblResults.PAT_NO, tblResults.PAT_SIZE
FROM tblResults
WHERE (((tblResults.L_PART_NO) In (select L_PART_NO from tblLock Where
L_EWO_NO like [forms].[frmCustomResultReport].[cmbLEWO] and L_PART_NO like
[forms].[frmCustomResultReport].[cmbLPart] and L_SKID_NO like
[forms].[frmCustomResultReport].[cmbLSKID] and L_MAT_TYPE like
[forms].[frmCustomResultReport].[cmbLMatType] and L_MAT_HEAT like
[forms].[frmCustomResultReport].[cmbLMatHeat] and L_HARD like
[forms].[frmCustomResultReport].[cmbLHard] and L_PLAT like
[forms].[frmCustomResultReport].[cmbLPlat] and L_TOP_COAT like
[forms].[frmCustomResultReport].[cmbLCoat] and L_THREAD like
[forms].[frmCustomResultReport].[cmbLThread])));
I am almost thinking that i need an Iff statement or something to make this
work, but I am not sure where. If anyone has any suggestions, that would be
great, Thank you!
~Erica~