Results 1 to 15 of 15
  1. #1
    Join Date
    Oct 2013
    Posts
    23

    Unanswered: If listBox item selected then make comboBox visible

    Hi,

    I know very little VB and require help building code that If a listBox item is selected then it makes comboBox visible.

    I have a List box of reports, if specific report is selected like 'ByEmployee' then I need combo box to become visible in which the user can select from a list of employees.

    Thanks,

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Replacing ListBoxName and ComboName by the actual names of the controls, you could use:
    Code:
    Private Sub ListBoxName_AfterUpdate()
    
        Me.ComboName.Visible = True
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Oct 2013
    Posts
    23
    Great thank you, however how do I Incorporate this code so that the combo only becomes visible if the list box item selected contains the word 'employee'.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so check the value of the selected listbox

    if mylistbox.value = 'employee' then
    Me.ComboName.Visible = True
    endif
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If the bound column of the listbox is the one that can display 'employee', use
    Code:
    Private Sub List_1_AfterUpdate()
    
        If Me.List_1.Value = "employee" Then
            Me.Combo_1.Visible = True
        Else
            Me.Combo_1.Visible = False
        End If
        
    End Sub
    If it's another column, then use:
    Code:
    Private Sub List_1_AfterUpdate()
    
        If Me.List_1.Column(x) = "employee" Then
            Me.Combo_1.Visible = True
        Else
            Me.Combo_1.Visible = False
        End If
        
    End Sub
    Where x is the index of the column, with the first (leftmost) column being Column(0).
    Have a nice day!

  6. #6
    Join Date
    Oct 2013
    Posts
    23
    Unfortunately they didn't work. I though I had it with the below. Where the employee report is on the 4th row of the list box.

    Private Sub rptList_AfterUpdate()

    If Me!rptList.Selected(4) = True Then
    Me!ComboSelectemp.Visible = True
    Else
    Me!ComboSelectemp.Visible = False
    End If
    End Sub

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    What does not work and what's the error message?
    Where does rptList.Selected(4) come from?
    Have a nice day!

  8. #8
    Join Date
    Oct 2013
    Posts
    23
    I got it from a MS form to obtain the selected item in a list box.

    There is no error, on selecting the employee report the related combo box does not become visible.

    Does the combo box need its viable property to be yes/no or does it not matter?

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    4th row of a list box

    Sinndho's code worked on column.


    the user needs to select the correct ro
    your code needs to test for that and take appropriate action
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Oct 2013
    Posts
    23
    I've reverted back and I still am unable to get it to become visible.

    See the attached.
    Attached Files Attached Files

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Of course it cannot work as the column ReportName of the table lkpReports does not contain "employee" in any row:
    Code:
    ID	Report Reference	Report Title		Report Name		Grouping
    1	CCL0001			All Complaints		rptComplaint List	1
    2	CCL0002			Internal Complaints	rptIntComplaint List	1
    3	CCL0003			External Complaints	rptExtComplaint List	1
    4	CCL0004			Complaints by Employee	rptComplaintbyEmployee	1
    5	CCL0005			Complaints by Customer	rptComplaintbyCustomer	1
    6	CCL0006			Complaints by Department rptComplaintbyDepartment 1
    7	CCL0007			All Outstanding					2
    8	CCL0008			Outstanding Internal's				2
    9	CCL0009			Outstanding External's				2
    10	CCL0010			Outstanding by Employee				2
    11	CCL0011			Outstanding by Customer				2
    12	CCL0012			Outstanding by Department			2
    13	CCL0013			All Closed					3
    14	CCL0014			Closed Internal's				3
    15	CCL0015			Closed External's				3
    16	CCL0016			Closed by Employee				3
    17	CCL0017			Closed by Customer				3
    18	CCL0018			Closed by Department				3
    Have a nice day!

  12. #12
    Join Date
    Oct 2013
    Posts
    23
    Ok so I thought if I changed the code to:

    Private Sub rptList_AfterUpdate()

    If Me!rptList.Column(2) = "Employee" Then
    Me!ComboSelectemp.Visible = True
    Else
    Me!ComboSelectemp.Visible = False
    End If
    End Sub

    However it still does not pick up employee in the report title column.

  13. #13
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Neither does the column [Report Title] contain "employee" in any row.
    I would work with the column Id:
    Code:
    Select Case Me!rptList.Column(0)
        Case 4, 10, 16
            Me!ComboSelectemp.Visible = True
        Case Else
            Me!ComboSelectemp.Visible = False
    End Select
    Have a nice day!

  14. #14
    Join Date
    Oct 2013
    Posts
    23
    This worked a treat - thank you all so, so much.

    Greatly appreciated

  15. #15
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

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
  •