Results 1 to 7 of 7
  1. #1
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86

    Expression to select which out of 5 fields equals 1 and use that field name as the result


    Is it possible to make an expression in a query that looks at 5 fields in that same query and finds the one that equals one and makes the name of that field the results for the expression?

    Thank you for all the help!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Probably, but readers need some context/code/description to offer more focused response.

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Only in VBA.

  4. #4
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    I figured it might have to be in VBA. Can you tell me how the code would look like? Let say as and example the field names are Field1, Field2, Field3, Field4, and Field5. How do I tell it to look at these fields and which ever one equals 1 use that field name as the result in a field called Results in a form.

    Thank you,

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    As orange says, some context would be helpful. The values in this column will always be 1 so only the column heading is any use to you. That means that you would have 5 different sets of data, all records with field1 = 1, all records with field2 = 1, etc. You can't have more than one field name per query so it would be 5 queries.

  6. #6
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    The query will only have one row and only one of the fields will have a number, the rest will be null or "". I just need it to find the field that has a number and return the field name. Hopefully that makes sense. I think it can be done using a single query.

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Open a record set
    Loop through fields to find when the value is 1.
    Then take the fieldname from the record set.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 30
    Last Post: 09-23-2015, 07:24 AM
  2. Select All Records Where Void equals False
    By burrina in forum Forms
    Replies: 4
    Last Post: 12-23-2012, 12:01 AM
  3. Unbound text box equals two conjoined fields
    By brharrii in forum Reports
    Replies: 1
    Last Post: 10-23-2012, 04:26 PM
  4. Replies: 8
    Last Post: 03-18-2012, 11:17 AM
  5. Replies: 3
    Last Post: 11-07-2011, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums