Results 1 to 10 of 10
  1. #1
    Juicejam is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Feb 2011
    Posts
    44

    Action after a listbox updates


    I have a listbox on a form which displays data based on the value of a textbox. I requery the listbox every second or so using the timer event on the form. What I want to accomplish is that whenever the listbox changes, i.e. a new row is added to the list, a subsequent action (in my case, a beep) occurs.

    I tried the afterupdate property of the listbox but that doesnt seem to work. The listbox is unbound.

    ANy help would be appreciated....

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    That event wouldn't fire with a requery. Offhand, you could test the count before and after the requery and compare them. That would obviously miss if a row was added and another deleted at the same time.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Juicejam is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Feb 2011
    Posts
    44
    Nice idea, and the simultaneous delete/add is not a factor as there is only one user.

    Could you suggest some code as to how to do this comparison? I would limit the number of rows to about 25 for the listbox.

    Thanks again.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    See my code in post 3 for the count

    https://www.accessforums.net/showthr...s-in-a-ListBox

    Put the count before into a variable, do the Requery, then compare the count after to the variable.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Juicejam is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Feb 2011
    Posts
    44
    ok I think I may know how to put something into a variable but how do I compare?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    For what you're doing

    If Before <> After Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Juicejam is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Feb 2011
    Posts
    44
    If Listbox.ListCount <> Listbox.ListCount then
    Beep
    End If

    I am really not familiar with comparisons nor using the <> symbols.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Well, logically that would never work because you're comparing the value to itself. Something like:

    Code:
    Dim lngCountBefore As Long
    Dim lngCountAfter As Long
    
    lngCountBefore = Me.ListboxName.ListCount - IIf(Me.ListboxName.ColumnHeads, 1, 0)
    Me.ListboxName.Requery
    lngCountAfter = Me.ListboxName.ListCount - IIf(Me.ListboxName.ColumnHeads, 1, 0)
    
    If lngCountBefore <> lngCountAfter Then
      MsgBox "Different count"
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Juicejam is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Feb 2011
    Posts
    44
    Ah now I get it. But what is the Columnhead reference for?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    It accounts for that setting of the listbox. If you are displaying column heads, your count will be off 1. In your case, it's irrelevant, but it's my standard code so I didn't edit it. You can drop that part from both lines.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Cascading Updates Help
    By rgrwatson85 in forum Database Design
    Replies: 5
    Last Post: 10-15-2011, 09:27 AM
  2. Need a querie that updates.
    By imlost2 in forum Queries
    Replies: 1
    Last Post: 08-20-2011, 09:06 AM
  3. query updates
    By kwooten in forum Queries
    Replies: 1
    Last Post: 06-14-2011, 11:43 AM
  4. Database Updates
    By avarusbrightfyre in forum Programming
    Replies: 1
    Last Post: 09-15-2010, 02:58 PM
  5. Version Updates
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 09-09-2010, 11:16 AM

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