Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2014
    Posts
    42
    Provided Answers: 1

    Answered: [VBA] Listboxes, Selections, and Requeries

    I have a form with a tab control and three listboxes on one of the tabs-- let's call them lbxMain, lbxList1, lbxList2. lbxMain has a list of records from a saved query, lbxList1 and 2 are both lists of metadata based on the selection in lbxMain with built in query data. None have control sources, all have the queries as row sources.

    I have vba (see below) at the end of a routine that essentially removes a record from lbxMain by changing a record and requerying the listbox. So update record, reuery lbxMain, record is removed; this requery works just fine!

    My problem: When the code moves on to requery lbxList1 and lbxList2, they are still keeping the metadata based on the previous selection, even though am changing the selection in lbxMain. Once I actually click on a new selection in lbxMain, the requery works fine. Because they are based on the selection in lbxMain with built in query data, it is almost like the ".Selected" property isn't enough to make access acknowledge the selection and update the criteria. If it helps, the criteria in the lbxList1 and 2 queries is Forms!frmMain!lbxMain

    Happy to expand on something if you need more details! Thanks

    Code:
    Me.lbxMain.Requery
        Me.lbxMain.Selected(-1) = True
        Me.lbxList1.Requery
        Me.lbxList2.Requery

  2. Best Answer
    Posted by pdevito3

    "Haha, just realized... Made the below change and it worked just fine:

    This:
    Code:
    Me.lbxMain.Selected(-1) = True
    To this:
    Code:
    Me.lbxMain = Me.lbxMain.ItemData(0)
    "


  3. #2
    Join Date
    Jun 2014
    Posts
    42
    Provided Answers: 1
    Haha, just realized... Made the below change and it worked just fine:

    This:
    Code:
    Me.lbxMain.Selected(-1) = True
    To this:
    Code:
    Me.lbxMain = Me.lbxMain.ItemData(0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •