Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2020
    Posts
    3

    Make field visible based on multi value combo box selection in another field

    I want to make an additional field visible depending on the combo box selection in another field. For example, ComboBox1 shows a dropdown list with a number of values: Option1, Option2, Option3, Other. If the user selects "Other", another field, which is invisible by default, will become visible, so the user can type additional text.
    The code below works perfectly for combo boxes in which multiple values are not allowed:



    Code:
    If ComboBox1.Value <> "Other" Then
            ShortText1.Visible = False
        End If
    If ComboBox1.Value = "Other" Then
            ShortText1.Visible = True
        End If
    The problem is that I can't find a way to make it work for combo boxes in which multiple values are allowed. I would like to make the additional field visible whether "Other" is the only selected value or one of several selected values.

    Any suggestions?
    Thank you.

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    I would recommend that you do not use a MVF at all and just normalise this value.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I also would not use mvf because of the problems they create. This is probably one of those problems, given that in such a control, if ANY record in a field it is bound to contains the value you want to use as a reference, the result will be True. **At least I believe that's how the .Selected(n) property of a mv combo works, which is the only thing I can think of that will allow you to test the control value at all. If it isn't bound, I doubt anything would work.

    If you're only dealing with a few choices, normalize the list or just use a value list in the combo.

    EDIT
    ** did some testing on this and found that you can determine if the .Selected(n) is True or False and it does work with a single record type of form IF the control is bound. If it isn't bound, it doesn't evaluate to either true or false. The .Selected(n) index is zero based BTW.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Join Date
    Dec 2020
    Posts
    3
    Thank you both! I agree that my design should improve, I'm learning along the way.

    Quote Originally Posted by Micron View Post
    did some testing on this and found that you can determine if the .Selected(n) is True or False and it does work with a single record type of form IF the control is bound. If it isn't bound, it doesn't evaluate to either true or false. The .Selected(n) index is zero based BTW.
    This worked perfectly:

    Code:
    If ComboBox1.Selected(n) Then
            ShortText1.Visible = True
        Else
            ShortText1.Visible = False
        End If
    Thanks for reminding me that the index is zero based... that would have driven me crazy if I hadn't thought about it

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Well, glad you got it working, but n was a placeholder for a number in my suggestion. I can't see how that would work for you - unless you're somehow setting n to a value.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Dec 2020
    Posts
    3
    Quote Originally Posted by Micron View Post
    Well, glad you got it working, but n was a placeholder for a number in my suggestion. I can't see how that would work for you - unless you're somehow setting n to a value.
    Yes, of course. I just replaced n with whatever number I needed in each specific case 🙂

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

Similar Threads

  1. Replies: 237
    Last Post: 12-07-2020, 10:52 AM
  2. Replies: 2
    Last Post: 06-17-2018, 12:07 AM
  3. Replies: 3
    Last Post: 03-26-2017, 01:26 PM
  4. Replies: 7
    Last Post: 12-09-2014, 12:24 PM
  5. Replies: 3
    Last Post: 02-21-2014, 11:36 AM

Tags for this Thread

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