Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Making a combo box visible based on user input (XP)

    Hi all,
    I have done something like this before but I don't have the nuances down to transfer my knowledge to this new task. On a form I have cmbResendLetter which is Yes/No. If the user changes it to "Yes" I would like cmbVerifyAddress and lbVerify both to become visible. Here's my guess at the code:

    If cmbResendLetter = "Yes" Then
    cmbVerifyAddress.Visible = True
    lblverify.Visible = True
    End If
    If cmbResendLetter = "No" Then
    cmbVerifyAddress.Visible = False
    lblverify.Visible = False
    End If

    There's a good chance this code isn't what I need, but if it is, my second problem is that I don't know where to place it...OnChange, OnExit, OnDirty...etc. I've been trying to reword it and I've placed it in just about every spot I thought it would work with no luck.

    Thanks for any help! Sarah

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Making a combo box visible based on user input (XP)

    You would place this in the After Update event of the cmbResendLetter combo box. The code can be simplified:

    Private Sub cmbResendLetter_AfterUpdate()
    Me.cmbVerifyAddress.Visible = (Me.cmbResendLetter = "Yes")
    Me.lblVerify.Visible = (Me.cmbResendLetter = "Yes")
    End Sub

  3. #3
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    Thanks Hans. I put your simplified code into the After Update event, but still nothing happens. Any thoughts? And thanks. Sarah

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Making a combo box visible based on user input (XP)

    You must select an item in the dropdown list of the combo box to trigger the code. If nothing still happens, could you tell us the following properties of the combo box?
    - Column Count
    - Column Widths
    - Row Source Type
    - Row Source
    - Bound Column

  5. #5
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    Hans,
    Here are the properties for both combo boxes:
    Column Count - 1
    Column Widths - (blank)
    Row Source Type - Value List
    Row Source - Yes; No
    Bound Column - 1

    Thanks! Sarah

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Making a combo box visible based on user input (XP)

    Hmm, it should work. Could you post a stripped down copy of your database? See <post#=401925>post 401925</post#> for instructions.

  7. #7
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    No problem. Here is the form and underlying table.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Making a combo box visible based on user input (XP)

    The combo box is bound to a Yes/No field. The values Yes and No of such a field are not the same as the strings "Yes" and "No", in fact Yes = True = -1 and No = False = 0. To display this correctly, the combo box must have to columns; the first one (hidden) contains -1 and 0, and the second one (displayed) contains "Yes" and "No".
    This also means that the code should not test for the string "Yes". The code can be further simplified to

    Private Sub cmbResendLetter_AfterUpdate()
    Me.cmbVerifyAddress.Visible = Me.cmbResendLetter
    End Sub

    You also need to set the visibility in the On Current event of the form, to keep it correct as you move from record to record.

    It isn't necessary to set the visibilty of the label, it will automatically match the visibility of the control it is attached to.

    See the attached modified version.

  9. #9
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    Thanks Hans for your patient help! Sarah

  10. #10
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    Hi again,
    The code is working fine and I added another line so that now three combo boxes' visibility is based on other inputs. However, for the first time, I needed to add a new record to the database and now I'm getting an error: Run Time error 94: Invalid use of Null and when I debug it goes to the code in the Private Sub Form Current (). It will still let me add the record if I close out of the VB window and don't fix the error, but it reoccurs each time I try to add a record. Thanks!

    Sarah

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Making a combo box visible based on user input (XP)

    Change the On Current event procedure to

    Private Sub Form_Current()
    Me.cmbVerifyAddress.Visible = Nz(Me.cmbResendLetter, False)
    End Sub

    The Nz function returns the second argument (False in this example) if the first argument is null.

  12. #12
    Star Lounger
    Join Date
    May 2002
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a combo box visible based on user input (XP)

    Thanks Hans,
    It is working great, and I appreciate your help!

    Sarah

Posting Permissions

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