Results 1 to 5 of 5
  1. #1
    Faiza is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    4

    how to disable or remove the selected listbox items for current

    I m using a listbox for my database which has list values, month names and it is a multi selection... means at a time more than one months can be selected.

    I used the following code to remove the selected items after used. for example if we used month jan then jan should not be highlighted so that it can not be used for the second time ... to avoid the duplicate claim of same month.

    Code:
    Dim lst As ListBox
    Dim intRowCtr As Integer
    Dim strBuild As String

    'Substitute your own List Box Name


    Set lst = Me![MonthFee]

    With lst
    If .ItemsSelected.Count = 0 Then Exit Sub
    For intRowCtr = 0 To .ListCount - 1
    If Not .Selected(intRowCtr) Then
    strBuild = strBuild & ";" & .ItemData(intRowCtr)
    End If
    Next intRowCtr

    If strBuild = "" Then strBuild = ";"

    .RowSource = Mid(strBuild, 2)
    End With

    The problem is that when jan remove from the list. and i select the next record for studid=2 here it shows the list of remaining months instead it should show the months of whole year for 2nd record .

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you need some code in the form current event to repopulate the listbox with all the months

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    to follow on,

    you might declare a public string called say monthlist in the form module

    and in the form open event put

    monthlist=monthfee.rowsource

    and in the form current event put

    monthfee.rowsource=monthlist

  4. #4
    Faiza is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    4
    Thanks for the reply but still in trouble.....

    List box "monthfee" is in the subform and student "id" is in the main form . For each "id", "monthfee" will be different. for example for "id=1" monthfee may be chosen as "jan, feb. so for only ID=1 in the monthfee list only two months should be removed..... and 2nd time against the same id, it should its remaining months only.

    For each selected id in the main form it should show the remaining monthlist in the subform. id there is a new id to add then it should show the whole 12 months i.s rowsource.
    waiting for reply, please

    Click image for larger version. 

Name:	Untitled.png 
Views:	8 
Size:	26.0 KB 
ID:	25277

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you would put the code in the subform, not the main form

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

Similar Threads

  1. Replies: 16
    Last Post: 03-31-2020, 10:19 AM
  2. Replies: 2
    Last Post: 03-27-2015, 08:48 AM
  3. Replies: 1
    Last Post: 01-22-2015, 10:55 AM
  4. Replies: 3
    Last Post: 10-23-2012, 03:32 PM
  5. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 PM

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