Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    13

    Unanswered: OR Statement in SQL

    Hello,

    I'm having a bit of trouble with an OR statement in SQL.

    I have a form in Access full of text boxes, I want the user to be able to enter data in these text boxes and then run a report based on the parameters they have set.

    I've made a query full of OR statements.

    For example

    Code:
    Select * From tblVoucher 
    Where VoucherNo = [frmReport]![txtvoucher] OR Surname = [frmReport]![txtsurname] OR IssuedBy = [frmReport]![txtIssuedBy]
    The above code is just an example but it doesn't seem to be working in the way I'm wanting.

    I have a lot of text boxes in my form and If the user enters data in 5 of them I want it to show me the records that meet all of those 5 criteria.

    At the min It just seems to be bringing me back records that meet the first criteria.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The OR means if any record matches one of the criteria, not all of the criteria. For records matching all of the criteria you'd have to use AND.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2010
    Posts
    13
    I understand that

    But lets say there are 10 text boxes. If I use an AND statement then all 10 textboxes need correct data entering into them.

    I'm wanting it so that if only a couple of text boxes has data in then then it will still show me the records.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Then you need to check each textbox to see if it has data or is null and only add it to your SQL statement if it contains data.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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