Consulting

Results 1 to 4 of 4

Thread: Solved: Excel/Access - SQL statement - WHERE/AND (Office '97)

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Solved: Excel/Access - SQL statement - WHERE/AND (Office '97)

    Hi There,

    I currently have the following SQL statement in a userform :-
    [vba] sSQL = "SELECT [RSA Errors].[ID], " & _
    "[RSA Errors].[Month], " & _
    "[RSA Errors].[DealerNumber], " & _
    "[RSA Errors].[DealerName], " & _
    "[RSA Errors].[CustomersName], " & _
    "[RSA Errors].[PolicyRegNo], " & _
    "[RSA Errors].[OriginalCM], " & _
    "[RSA Errors].[CallReason], " & _
    "[RSA Errors].[Comments], " & _
    "[RSA Errors].[GenuineError], " & _
    "[RSA Errors].[AmendmentComments], " & _
    "[RSA Errors].[Scheme] " & _
    "FROM [RSA Errors] " & _
    "WHERE [RSA Errors].[Month] LIKE '%" & strMonth & "%' " & _
    "AND [RSA Errors].[GenuineError] '%" & strRecords & "%' " & _
    "ORDER BY [RSA Errors].[ID] AND [RSA Errors].[OriginalCM];"[/vba]
    This code doesn't locate any records unless i remove the AND statement. Is anyone able to suggest a solution as to why the inclusion of the AND statement doesn't work?

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You should frst check what strRecords actually contains. Then you should probably add an operator in the clause.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    like xld said

    AND [RSA Errors].[GenuineError] '%" & strRecords & "%' "

    probably needs

    AND [RSA Errors].[GenuineError] = '%" & strRecords & "%' "
    or
    AND [RSA Errors].[GenuineError] > '%" & strRecords & "%' "
    or
    AND [RSA Errors].[GenuineError] < '%" & strRecords & "%' "
    or
    AND [RSA Errors].[GenuineError] LIKE '%" & strRecords & "%' "

    or whatever

  4. #4
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    d'oh i forgot the LIKE operator!

    thanks!
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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