Results 1 to 8 of 8
  1. #1
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77

    Using an IIf expression to check a column with multiple values

    We do checks for errors on customer's shipments and run a reporting registry on errors found.

    Each check may result in one or more errors identified. It may also result in no errors identified.

    I have an access table that contains information about each check done. In the table, there is a column "Errorsfound" that keeps information about whether each particular revealed an error, if there were more than one error, and the nature of the error.



    In the column "Errorsfound", the user may choose to check one or more values:
    -No errors found
    -Error A
    -Error B
    -Error C

    (Of course, logically it will make no sense for the user to check both the value "No errors found" and the value "Error A", while it would make sense to check "Error A" together with "Error B" since both can be present at the same time. However, I do not want to leave "No errors found" out, since I would then have no way to see if the user has chosen to report no errors or the user has forgotten to report.)

    Now;
    For ease of reporting, I would like a column that reveals whether the particular record has any errors. Let's call this column "Any_errors_found". I would like the column to display the value "1" if "Errorsfound" has one or more of the values that signifies that errors were found. I do not want the value "1" to appear if "Errorsfound" has the value that signifies that no errors were found.

    I have tried making an updating query that inserts the value "1" into a column if the column "Errorsfound" contains either "Error A", "Error B" or "Error C". This works, but it quickly becomes impractical as I have to run that updating query regularly. I can do it with a macro, but it is still impractical.

    I would like instead for a calculated field to show if any errors were found. I tried to do this using an "IIf" expression. However, cannot seem to make a calculated field that is based on whether the column "Errorsfound" has a particular value.

    Why is this, and what do I do instead?

    I have made an image of how this would ideally look:
    Click image for larger version. 

Name:	errors.png 
Views:	19 
Size:	4.3 KB 
ID:	31602

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    find 'error' with space:

    iif(INSTR([ErrorsFound],"Error ")>0,1,0)

  3. #3
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    Quote Originally Posted by ranman256 View Post
    find 'error' with space:

    iif(INSTR([ErrorsFound],"Error ")>0,1,0)
    Access doesn't seem to recognize ErrorsFound. When typing the expression in the expression generator, usually the column name will pop up when starting to type its name, but when typing ErrorsFound nothing auto-completes its name, and I can't seem to make the line of code work. This is not only for IIf expressions, I can't seem to use the name of column ErrorsFound in any generated expression.
    Last edited by Nanuaraq; 12-12-2017 at 04:02 AM.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    sounds like you are using a calculated field in a table. Suggest use a query instead. However since you appear to be using a multivalue field, I'm not sure you can do that. You'll have to try it and see.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    whether each particular revealed an error
    Your data should be structured like
    particular ErrorType ErrCount
    1 A 1
    1 C 1
    2 A 1
    3 B 1
    3 C 1
    4 A 1
    The form should not allow user to not make a choice from a listbox of errors. If there are no errors, you could skip writing that particular to the errors table, or use an identifier for no error and insert 1. This could allow you to count any type of error, including those where there were none. I think I can safely say that most of us here would use neither calculated fields in tables, nor work directly on them over using forms.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    Apparently, it is not possible for me to use a calculated field on basis of data from a multivalue field. I have tried to do that in a table, and I have also tried to use a query that queries the multivalue field and then makes an expression based on the multivalue field in the query. I am told by access that this is not valid.

    Might it be possible for me to convert the multivalue field to a text string? I have had no success in doing that, but it would solve my problem. How do I convert a multivalue field into text by use of a calculated field?

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    it should be a separate table as micron suggested in post #5 and displayed as a subform on your main form

    converting to text string is not a good way to go, you will just be building more problems for yourself and as such not something I would be prepared to help with.

    You can display the results of the table as a text string - google 'vba concatrelated' for the process

  8. #8
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    created new thread for the particular issue

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

Similar Threads

  1. Replies: 14
    Last Post: 07-13-2015, 12:47 PM
  2. Replies: 1
    Last Post: 09-11-2014, 05:53 AM
  3. multiple check box values - update table
    By joycesolomon in forum Forms
    Replies: 8
    Last Post: 08-11-2014, 08:02 AM
  4. Replies: 1
    Last Post: 04-30-2014, 01:05 AM
  5. Replies: 5
    Last Post: 04-25-2014, 01:17 PM

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