If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Need Help with Filtering a Query/Report!!
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! -- ~Erica~ |
#2
|
|||
|
|||
Need Help with Filtering a Query/Report!!
-----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----- Eka1618 wrote: 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! |
#3
|
|||
|
|||
Need Help with Filtering a Query/Report!!
Thanks for the help Foster,
I ended up solving my problem using the method that Dale suggests in this thread: http://www.microsoft.com/communities...3-ba009e0e48b9 I knew that my quotes were probably wrong though... I was just really stuck on this one. I'm not to great with reports yet, I'm still learning. Thank You! -- ~Erica~ "MGFoster" wrote: -----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----- Eka1618 wrote: 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! |
Thread Tools | |
Display Modes | |
|
|