Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listbox with event (Access 2002)

    If I have a listbox with either the after update event or click event associated with codes (to search a record on the form), I always have highlighted multiple entries even though in the multi select I set it to none already. Does anyone have a solution or explanation to that? If there is no code with those event, then the select is always one single entry.

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listbox with event (Access 2002)

    That is not normal behavior, and as far as I know, it is not a known bug in Access 2002. I have never seen it on one of the PC's I work with at home or at work.

    Is your system low on resources? The overhead of running code might just push things over the edge. And, although less likely, it might be a problem with the video drivers and/or video memory.

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox with event (Access 2002)

    I don't think it has anything to do with system resources. I just created a form with subform (customer and orders on the Northwind database) and then add a listbox using the Wizard to search for the customer. After I had selected a customer and then move on to pick another, the previously selected one was still highlighted. Now I got two highlighted. I went on to create an unbound form and just placed a listbox there pointing to the customer table, it worked just fine.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listbox with event (Access 2002)

    Hmmm, again, this is not as it should be, and it is not what I get (I did test this on Access 2002, just to see if I had overlooked something). I don't know what to think of it. Although I don't know if it will help, you might try Detect and Repair from the Help menu...

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Listbox with event (Access 2002)

    I've often seen this same problem with listboxes used for record navigation with bound form. For demonstration purposes, I modified the Customer Orders form in Northwind.mdb by adding an unbound, single-select listbox to form header named List1. The listbox's RowSource is:

    SELECT [Customers].[CustomerID], [Customers].[CompanyName] FROM [Customers]

    Also modified form to allow edits, and added CustomerID field to be able to locate records with listbox. The attached illustration shows form "before and after" I modified the generic "wizard" code for listbox's AfterUpdate event (where current record is Blauer See Delikatessen). Modified code:

    Option Compare Database
    Option Explicit

    ' Module-level variable:
    Dim bFlag As Boolean

    Private Sub Form_Current()

    With Me
    If bFlag = False Then
    .List1 = .CustomerID
    Else
    ' Listbox value already set by AfterUpdate event
    ' Reset flag:
    bFlag = False
    End If
    End With

    End Sub

    Private Sub Form_Open(Cancel As Integer)
    'Initialize module-level variable:
    bFlag = False
    End Sub

    Private Sub List1_AfterUpdate()

    ' Find the record that matches the control.
    Dim rst As DAO.Recordset
    Set rst = Me.Recordset.Clone

    With Me
    bFlag = True
    rst.FindFirst "<!t>[CustomerID]<!/t> = '" & .List1 & "'"
    .Bookmark = rst.Bookmark
    .List1 = .CustomerID
    End With

    Set rst = Nothing

    End Sub

    Note the use of a module-level variable to keep track of when to set value of listbox to CustomerID on form's On Current event (used to "synchronize" listbox with current record). If listbox value set by AfterUpdate event, then the flag is set to True so the form's Current event "knows" not to set value again, and instead resets flag to False. This seems like a lot of extra work, but if you look at the before & after images, the "after" looks a lot better than the "before" (recall this is NOT a multi-select listbox). The listbox displays only one selection for current record, whether you navigate by using listbox, or the standard navigation buttons. I am not aware of any good explanation or cause for this flaky behavior. You may be able to adapt this technique for forms where you experience this problem.

    HTH
    Attached Images Attached Images

Posting Permissions

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