MS ACCESS How to Disable line items in listbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny6685
    New Member
    • Dec 2014
    • 66

    #1

    MS ACCESS How to Disable line items in listbox?

    Hi Guys,

    I have two listbox A and B in my form, both the listboxes are having same source to one of my table say it as TABLEA. Now I want to disable few line items in listbox B when the user select those items in listbox A.

    Eg. Listbox A and B are having employee names, if the user selects "JOHNY" name in listbox A the line item "JOHNY" in listbox should be shown but disabled.


    Please advise on how to complete this task.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    "items" in a listbox are not objects that have enable/disable properties. They are just records that have text. You may be able to do some formatting (just maybe) on certain lines if you add a Selected field to your TABLEA and use the OnClick or OnDblClick events to change the value of the Selected field, but you would have to play with that a little bit.

    Comment

    • johny6685
      New Member
      • Dec 2014
      • 66

      #3
      Ok, so is there a way to removeitems from LISTBOXB that are selected in LISTBOXA?

      Comment

      • johny6685
        New Member
        • Dec 2014
        • 66

        #4
        Ok... Here I have coded with an additional table created for that.



        Code:
        Private Sub lstRowDtls_AfterUpdate()
        Dim varSelected, lstitm As Variant
        lstColData.Requery
            
            If Me.Subform.Visible = True Then
                Me.Subform.Visible = False
            End If
            
            DoCmd.SetWarnings False
            DoCmd.RunSQL "DELETE * FROM tbltmpColmlst"
            DoCmd.SetWarnings True
        
            
            For Each varSelected In lstRowDtls.ItemsSelected
            lstitm = Me.lstRowDtls.ItemData(varSelected)
            DoCmd.SetWarnings False
            DoCmd.RunSQL "INSERT INTO tbltmpColmlst (Elemenators) VALUES ('" & lstitm & "')"
            DoCmd.SetWarnings True
            Next varSelected
        
           Me.lstColData.Requery
           
        End Sub
        And my LISTBOXB Rowsource as below

        Code:
        SELECT FilterColumns.FieldNames
        FROM FilterColumns
        WHERE (((FilterColumns.FieldNames) Not In (SELECT Elemenators FROM [tbltmpColmlst])) AND ((FilterColumns.Required)=True));

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          So you got it to work?

          Comment

          Working...