Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Incorrect selections (A2K)

    What am I not seeing?

    The following code should extract only

    Functions = 1
    and
    RA's = 500 or 555 or 600

    The file being searched only has 600's so only 600's with a Funtion 1 should appear,
    yet it also displays Function 5's and 11's

    Private Sub prv_00250_Click()
    Dim strFunction As String
    Dim strRA As String
    Dim strCombine As String
    strFunction = "F00_Function = 1"
    strRA = "F01_RA_No = 500 Or F01_RA_No = 555 Or F01_RA_No = 600"
    strCombine = strFunction & " AND " & strRA
    On Error GoTo Err_Click
    DoCmd.OpenReport ReportName:="rpt 00250 - Lotto - Receiving", View:=acViewPreview, _
    WhereCondition:=strCombine
    DoCmd.RunCommand acCmdZoom100
    Exit Sub
    Err_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    Thanks in advance for any help offered
    Cheers,
    Andy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Incorrect selections (A2K)

    And has precedence above Or: A And B Or C Or D is interpreted as (A And Or C Or D. To keep the Ors together, you must place parentheses around them: A And (B Or C Or D).

    In your example:

    strRA = "(F01_RA_No = 500 Or F01_RA_No = 555 Or F01_RA_No = 600)"

    Another possibility would be to use In (...):

    strRA = "F01_RA_No In (500, 555, 600)"

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Incorrect selections (A2K)

    Hans,

    I truly never fail to be amazed at your quick and accurate responses. I always hope, as I've mentioned before, that there are others that gain as much help from my questions and your answers as I do.

    Thanks again and
    Cheers,
    Andy

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Incorrect selections (A2K)

    Hate Fridays!

    In the same vein:

    Private Sub prv_00350_Click()
    Dim strFunction As String
    Dim strRA As String
    Dim strCombine As String
    strFunction = "F00_Function = 5 Or F00_Function = 11 Or F00_Function = 20 Or F00_Function = 23"

    strRA = "F01_RA_No In (500)"

    strCombine = strFunction & " AND " & strRA
    On Error GoTo Err_Click
    DoCmd.OpenReport ReportName:="rpt 00350 - Lotto - Repaired", View:=acViewPreview, _
    WhereCondition:=strCombine
    DoCmd.RunCommand acCmdZoom100
    Exit Sub
    Err_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    I get a couple of strRA's = 600 in the middle of my 500's

    I also tried :

    strRA = "F01_RA_No = 500"

    I'm obviously missing something basic.
    Cheers,
    Andy

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Incorrect selections (A2K)

    It's exactly the same problem, with exactly the same solution. Change the line

    strFunction = "F00_Function = 5 Or F00_Function = 11 Or F00_Function = 20 Or F00_Function = 23"

    to

    strFunction = "(F00_Function = 5 Or F00_Function = 11 Or F00_Function = 20 Or F00_Function = 23)"

    or

    strFunction = "F00_Function In (5, 11, 20, 23)"

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Incorrect selections (A2K)

    Sigh!

    I hope I'm driving you to drink.
    Cheers,
    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •