By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

MS ACCESS How to Disable line items in listbox?

P: 66
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.
Feb 18 '15 #1
Share this Question
Share on Google+
4 Replies


Seth Schrock
Expert 2.5K+
P: 2,951
"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.
Feb 18 '15 #2

P: 66
Ok, so is there a way to removeitems from LISTBOXB that are selected in LISTBOXA?
Feb 18 '15 #3

P: 66
Ok... Here I have coded with an additional table created for that.



Expand|Select|Wrap|Line Numbers
  1. Private Sub lstRowDtls_AfterUpdate()
  2. Dim varSelected, lstitm As Variant
  3. lstColData.Requery
  4.  
  5.     If Me.Subform.Visible = True Then
  6.         Me.Subform.Visible = False
  7.     End If
  8.  
  9.     DoCmd.SetWarnings False
  10.     DoCmd.RunSQL "DELETE * FROM tbltmpColmlst"
  11.     DoCmd.SetWarnings True
  12.  
  13.  
  14.     For Each varSelected In lstRowDtls.ItemsSelected
  15.     lstitm = Me.lstRowDtls.ItemData(varSelected)
  16.     DoCmd.SetWarnings False
  17.     DoCmd.RunSQL "INSERT INTO tbltmpColmlst (Elemenators) VALUES ('" & lstitm & "')"
  18.     DoCmd.SetWarnings True
  19.     Next varSelected
  20.  
  21.    Me.lstColData.Requery
  22.  
  23. End Sub
And my LISTBOXB Rowsource as below

Expand|Select|Wrap|Line Numbers
  1. SELECT FilterColumns.FieldNames
  2. FROM FilterColumns
  3. WHERE (((FilterColumns.FieldNames) Not In (SELECT Elemenators FROM [tbltmpColmlst])) AND ((FilterColumns.Required)=True));
Feb 18 '15 #4

Seth Schrock
Expert 2.5K+
P: 2,951
So you got it to work?
Feb 18 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.