Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Deselect last item selected in multi select listbox

Discussion in 'Information Technology' started by Mr B, Jul 28, 2006.

  1. Mr B

    Mr B
    Expand Collapse
    Guest

    How do I deselect the last item selected in a multi select listbox?

    I have tried various iterations of code with no success:

    Mr B
     
  2. Loading...

    Similar Threads Forum Date
    Last Blog Blogs Oct 14, 2016
    That Pesky Last 1% Blogs Oct 12, 2016
    Self Songs Of The Last 10 Years Blogs Oct 2, 2016
    Difficult Areas Of Turban And How To Remedy It ? Is A Plastic Cup For Your Ears The Answer Health & Nutrition Jun 4, 2016
    Alone At Last Blogs May 1, 2016

  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    The last chronologically, or the last sequentially?

    For sequentially, you can use:

    Me.List0.Selected(Me.List0.ItemsSelected.Item(Me.List0.ItemsSelected.Count -
    1)) = False

    (replace List0 with the actual name of your listbox)

    For chronologically, there's nothing built into Access that I'm aware of.
    You might be able to put code in the list box's Click event to determine the
    order in which the entries were selected, but it would be messy.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Mr B" <MrB@discussions.microsoft.com> wrote in message
    news:9373CE17-3FCE-43C6-BF23-B334AA089B11@microsoft.com...
    > How do I deselect the last item selected in a multi select listbox?
    >
    > I have tried various iterations of code with no success:
    >
    > Mr B
     
  4. Mr B

    Mr B
    Expand Collapse
    Guest

    Doug,

    Thanks for the reply.

    Unfortunately, it is the chronological selection that I am looking for.

    A more indepth description of what I am attempting to do is:

    I have a list of items that are about to be added to second list (multiple
    selections). However, as the user makes a selection, I am checking the bound
    value to see if that selection is already in the second list. If it is, I am
    notifying the user that the selection is already in the list. I just need to
    unselect the item they selected to trigger the After Update event if the list
    box.

    I do already have the bound column value for the selected item. Can I some
    way use that to return the selecteditem value and unselect it? (Hope that was
    clear enough.)


    Mr B


    "Douglas J Steele" wrote:

    > The last chronologically, or the last sequentially?
    >
    > For sequentially, you can use:
    >
    > Me.List0.Selected(Me.List0.ItemsSelected.Item(Me.List0.ItemsSelected.Count -
    > 1)) = False
    >
    > (replace List0 with the actual name of your listbox)
    >
    > For chronologically, there's nothing built into Access that I'm aware of.
    > You might be able to put code in the list box's Click event to determine the
    > order in which the entries were selected, but it would be messy.
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > news:9373CE17-3FCE-43C6-BF23-B334AA089B11@microsoft.com...
    > > How do I deselect the last item selected in a multi select listbox?
    > >
    > > I have tried various iterations of code with no success:
    > >
    > > Mr B

    >
    >
    >
     
  5. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    If you're already checking whether or not a particular selection exists in
    the second list, just set its Selected property to False.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Mr B" <MrB@discussions.microsoft.com> wrote in message
    news:FA533AD0-B3A7-4A74-B9E9-7E6C4FA3807A@microsoft.com...
    > Doug,
    >
    > Thanks for the reply.
    >
    > Unfortunately, it is the chronological selection that I am looking for.
    >
    > A more indepth description of what I am attempting to do is:
    >
    > I have a list of items that are about to be added to second list (multiple
    > selections). However, as the user makes a selection, I am checking the

    bound
    > value to see if that selection is already in the second list. If it is, I

    am
    > notifying the user that the selection is already in the list. I just need

    to
    > unselect the item they selected to trigger the After Update event if the

    list
    > box.
    >
    > I do already have the bound column value for the selected item. Can I some
    > way use that to return the selecteditem value and unselect it? (Hope that

    was
    > clear enough.)
    >
    >
    > Mr B
    >
    >
    > "Douglas J Steele" wrote:
    >
    > > The last chronologically, or the last sequentially?
    > >
    > > For sequentially, you can use:
    > >
    > >

    Me.List0.Selected(Me.List0.ItemsSelected.Item(Me.List0.ItemsSelected.Count -
    > > 1)) = False
    > >
    > > (replace List0 with the actual name of your listbox)
    > >
    > > For chronologically, there's nothing built into Access that I'm aware

    of.
    > > You might be able to put code in the list box's Click event to determine

    the
    > > order in which the entries were selected, but it would be messy.
    > >
    > > --
    > > Doug Steele, Microsoft Access MVP
    > > http://I.Am/DougSteele
    > > (no e-mails, please!)
    > >
    > >
    > > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > > news:9373CE17-3FCE-43C6-BF23-B334AA089B11@microsoft.com...
    > > > How do I deselect the last item selected in a multi select listbox?
    > > >
    > > > I have tried various iterations of code with no success:
    > > >
    > > > Mr B

    > >
    > >
    > >
     
  6. Mr B

    Mr B
    Expand Collapse
    Guest

    I know it sounds as if that is all I would have to do. Just set its Selected
    property to false. However, the way I'm trying to do it rigth now, it seems
    to work for a single selection, but not if another selection was made first.

    Here is the code that I am trying to use:

    'read the ProductID for the selected Product
    Dim lngProductID As Long
    lngProductID = Me.lstProducts.Column(0)
    Dim strMsg As String
    Dim varSelCnt
    'check to see if that Product is already on the list
    varRecCnt = DCount("ItemID", "tblNextList", "ProductID = " & lngProductID &
    "")
    If varRecCnt > 0 Then
    varSelCnt = Me.lstProducts.ItemsSelected.Count
    If varSelCnt > 0 Then
    strMsg = "That produce it already in the Next List"
    MsgBox strMsg, vbInformation + vbOKOnly, "Duplicated Product"
    Me.lstProducts.Selected(varSelCnt) = False
    End If
    End If

    I think I may need to try to hold on to a different value than the
    ItemsSelected.count but I am not sure just what I do need to try.

    Thanks for any additional help.

    Mr B


    "Douglas J Steele" wrote:

    > If you're already checking whether or not a particular selection exists in
    > the second list, just set its Selected property to False.
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > news:FA533AD0-B3A7-4A74-B9E9-7E6C4FA3807A@microsoft.com...
    > > Doug,
    > >
    > > Thanks for the reply.
    > >
    > > Unfortunately, it is the chronological selection that I am looking for.
    > >
    > > A more indepth description of what I am attempting to do is:
    > >
    > > I have a list of items that are about to be added to second list (multiple
    > > selections). However, as the user makes a selection, I am checking the

    > bound
    > > value to see if that selection is already in the second list. If it is, I

    > am
    > > notifying the user that the selection is already in the list. I just need

    > to
    > > unselect the item they selected to trigger the After Update event if the

    > list
    > > box.
    > >
    > > I do already have the bound column value for the selected item. Can I some
    > > way use that to return the selecteditem value and unselect it? (Hope that

    > was
    > > clear enough.)
    > >
    > >
    > > Mr B
    > >
    > >
    > > "Douglas J Steele" wrote:
    > >
    > > > The last chronologically, or the last sequentially?
    > > >
    > > > For sequentially, you can use:
    > > >
    > > >

    > Me.List0.Selected(Me.List0.ItemsSelected.Item(Me.List0.ItemsSelected.Count -
    > > > 1)) = False
    > > >
    > > > (replace List0 with the actual name of your listbox)
    > > >
    > > > For chronologically, there's nothing built into Access that I'm aware

    > of.
    > > > You might be able to put code in the list box's Click event to determine

    > the
    > > > order in which the entries were selected, but it would be messy.
    > > >
    > > > --
    > > > Doug Steele, Microsoft Access MVP
    > > > http://I.Am/DougSteele
    > > > (no e-mails, please!)
    > > >
    > > >
    > > > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > > > news:9373CE17-3FCE-43C6-BF23-B334AA089B11@microsoft.com...
    > > > > How do I deselect the last item selected in a multi select listbox?
    > > > >
    > > > > I have tried various iterations of code with no success:
    > > > >
    > > > > Mr B
    > > >
    > > >
    > > >

    >
    >
    >
     
  7. Mr B

    Mr B
    Expand Collapse
    Guest

    Just thought I'd post back to let you know that I finally got it to work as I
    needed it to. Below is the code that finally did the job.

    'read the ProductID for the selected Product
    Dim lngProductID As Long
    lngProductID = Me.lstProducts.Column(0)
    Dim strMsg As String
    Dim varSelCnt
    Dim frm As Form
    Dim ctl As Control
    Dim varItm As Variant
    'check to see if that Product is already on the list
    varRecCnt = DCount("ItemID", "tblNextList", "ProductID = " & lngProductID &
    "")
    If varRecCnt > 0 Then
    varSelCnt = Me.lstProducts.ItemsSelected.Count
    If varSelCnt > 0 Then
    strMsg = "That produce it already in the Grocery List"
    MsgBox strMsg, vbInformation + vbOKOnly, "Duplicated Product"
    'Me.lstProducts.Selected(varSelCnt) = False
    'add all selected products to the Grocery List
    Set frm = Forms!frmNeedsList
    Set ctl = frm!lstProducts
    For Each varItm In ctl.ItemsSelected
    If ctl.ItemData(varItm) = lngProductID Then
    Me.lstProducts.Selected(varItm) = False
    End If
    Next varItm
    End If
    End If

    I actaully had to iterate through each of the items in the list, checking
    each item to see if that was the item that contained the ProductID that I had
    captured to a variable in the OnClick event of the control. The code that
    really does the trick is:

    For Each varItm In ctl.ItemsSelected
    If ctl.ItemData(varItm) = lngProductID Then
    Me.lstProducts.Selected(varItm) = False
    End If
    Next varItm

    The only reason that I posted this back was so that in the event that anyone
    else every needed to accomplish something like this, perhaps they would not
    have to spend as much time figuring it out as I did.

    Doug, thanks so much for all your help. You have helped me many times. Just
    doing a search in the newsgroups for something I need to know about will most
    times help me accomplish the task. Your postings, along with the many others
    who attempt to help with their postings, are really appreciated by many of us
    who frequent these newsgroups.

    Mr B


    "Mr B" wrote:

    > I know it sounds as if that is all I would have to do. Just set its Selected
    > property to false. However, the way I'm trying to do it rigth now, it seems
    > to work for a single selection, but not if another selection was made first.
    >
    > Here is the code that I am trying to use:
    >
    > 'read the ProductID for the selected Product
    > Dim lngProductID As Long
    > lngProductID = Me.lstProducts.Column(0)
    > Dim strMsg As String
    > Dim varSelCnt
    > 'check to see if that Product is already on the list
    > varRecCnt = DCount("ItemID", "tblNextList", "ProductID = " & lngProductID &
    > "")
    > If varRecCnt > 0 Then
    > varSelCnt = Me.lstProducts.ItemsSelected.Count
    > If varSelCnt > 0 Then
    > strMsg = "That produce it already in the Next List"
    > MsgBox strMsg, vbInformation + vbOKOnly, "Duplicated Product"
    > Me.lstProducts.Selected(varSelCnt) = False
    > End If
    > End If
    >
    > I think I may need to try to hold on to a different value than the
    > ItemsSelected.count but I am not sure just what I do need to try.
    >
    > Thanks for any additional help.
    >
    > Mr B
    >
    >
    > "Douglas J Steele" wrote:
    >
    > > If you're already checking whether or not a particular selection exists in
    > > the second list, just set its Selected property to False.
    > >
    > > --
    > > Doug Steele, Microsoft Access MVP
    > > http://I.Am/DougSteele
    > > (no e-mails, please!)
    > >
    > >
    > > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > > news:FA533AD0-B3A7-4A74-B9E9-7E6C4FA3807A@microsoft.com...
    > > > Doug,
    > > >
    > > > Thanks for the reply.
    > > >
    > > > Unfortunately, it is the chronological selection that I am looking for.
    > > >
    > > > A more indepth description of what I am attempting to do is:
    > > >
    > > > I have a list of items that are about to be added to second list (multiple
    > > > selections). However, as the user makes a selection, I am checking the

    > > bound
    > > > value to see if that selection is already in the second list. If it is, I

    > > am
    > > > notifying the user that the selection is already in the list. I just need

    > > to
    > > > unselect the item they selected to trigger the After Update event if the

    > > list
    > > > box.
    > > >
    > > > I do already have the bound column value for the selected item. Can I some
    > > > way use that to return the selecteditem value and unselect it? (Hope that

    > > was
    > > > clear enough.)
    > > >
    > > >
    > > > Mr B
    > > >
    > > >
    > > > "Douglas J Steele" wrote:
    > > >
    > > > > The last chronologically, or the last sequentially?
    > > > >
    > > > > For sequentially, you can use:
    > > > >
    > > > >

    > > Me.List0.Selected(Me.List0.ItemsSelected.Item(Me.List0.ItemsSelected.Count -
    > > > > 1)) = False
    > > > >
    > > > > (replace List0 with the actual name of your listbox)
    > > > >
    > > > > For chronologically, there's nothing built into Access that I'm aware

    > > of.
    > > > > You might be able to put code in the list box's Click event to determine

    > > the
    > > > > order in which the entries were selected, but it would be messy.
    > > > >
    > > > > --
    > > > > Doug Steele, Microsoft Access MVP
    > > > > http://I.Am/DougSteele
    > > > > (no e-mails, please!)
    > > > >
    > > > >
    > > > > "Mr B" <MrB@discussions.microsoft.com> wrote in message
    > > > > news:9373CE17-3FCE-43C6-BF23-B334AA089B11@microsoft.com...
    > > > > > How do I deselect the last item selected in a multi select listbox?
    > > > > >
    > > > > > I have tried various iterations of code with no success:
    > > > > >
    > > > > > Mr B
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >
     

Share This Page