Need Help with Filtering a Query/Report!!

E

Eka1618

Hello,

I am trying to filter a subReport with query for a RecordSource (qryResults).

Here is the SQL for my the query:

SELECT tblResults.Q_INC, tblResults.SAMPLE_NO, tblResults.FAILED_AT,
tblResults.P_F, tblResults.FAIL_LEVEL, tblResults.ON_OFF,
tblResults.FAIL_TORQ, tblResults.PASS_VALUE, tblResults.TENSION,
tblResults.NOTES, tblResults.OBSERVATIONS, tblResults.L_PART_NO,
tblResults.K_PART_NO, tblResults.PAT_NO, tblResults.PAT_SIZE,
tblResults.FAIL_TRQ_LEVEL, tblResults.SHROUD_OVAL, tblResults.L_ID,
tblResults.K_ID, tblResults.L_FAILURE_MODE, tblResults.K_FAILURE_MODE
FROM tblResults;


The master/Child link is: Q_INC

When the subform loads I want it to filter in two different conditions:

If Me.Parent.K_ID.Value = Null Then
Me.RecordSource = "qryResults"
Me.Filter = "L_ID = " & Me.Parent!L_ID
Me.FilterOn = True
Else
Me.RecordSource = "qryResults"
Me.Filter = "L_ID = " & Me.Parent!L_ID And "K_ID = " & Me.Parent!K_ID
Me.FilterOn = True
End If


This code does not work, and I do not know what to do. I have tried many
other methods, I'm not sure what to do...

If anyone has any suggestion please let me know. Thank you!
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have one error that I spotted:

Me.Filter = "L_ID = " & Me.Parent!L_ID And "K_ID = " & Me.Parent!K_ID

should be like this:

Me.Filter = "L_ID = " & Me.Parent!L_ID & " And K_ID = " & Me.Parent!K_ID

If the data types of L_ID and K_ID are Text then the line should be like
this:

Me.Filter = "L_ID = '" & Me.Parent!L_ID & "' And K_ID = '" & _
Me.Parent!K_ID & "'"

Note the single quote as the Text data delimiter.

My email formatter wrapped the line so I put in the VBA line extender
"_" (underline character) at the end of the line.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSL7vMYechKqOuFEgEQKFsgCgvuUQKeQjLbOsTj3zhyEm4/+uaD8An0GE
j9LFXXn9q+GKosZS6dB19Iu3
=7GAs
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top