Results 1 to 3 of 3
  1. #1
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40

    Cancel Selection Event for ListBox

    Hello,
    I have an unbound no-multi-select listbox. When user changes selection in the listbox I need to run a check to verify if some conditions are met. If not, I need to set listbox selection back to previous one and set focus to a textbox that didn’t pass the check. I tried a number of things with no luck. Below is a sample pseudocode that I had in mind, but obviously it doesn’t work. Any suggestions are greatly appreciated!



    ‘*****pseudocode*****
    ‘g_MyListIndex – global variable
    ‘CheckEntry is just a Boolean function to do certain checks

    Private Sub lstMyListBox_AfterUpdate()
    If not CheckEntry(me.txtMyTextbox) then
    Me.lstMyListBox.setfocus
    Me.lstMyListBox.ListIndex = g_MyListIndex
    Me.txtMyTextbox.setfocus
    Else
    g_MyListIndex = me.lstMyListBox.ListIndex
    End if

  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,521
    Haven't tested this, but generally you'd use the before update event. Including this line would stop the update:

    Cancel = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40
    Quote Originally Posted by pbaldy View Post
    Haven't tested this, but generally you'd use the before update event. Including this line would stop the update:

    Cancel = True
    I've tried that and it seemed to work only on bounded listboxes; it didn't work in my case .

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

Similar Threads

  1. Replies: 2
    Last Post: 08-03-2010, 10:16 AM
  2. Replies: 3
    Last Post: 06-04-2010, 12:47 PM
  3. Yes No Cancel MsgBox
    By Rick West in forum Forms
    Replies: 5
    Last Post: 04-14-2010, 08:57 AM
  4. Cancel listbox selection
    By vba-dev in forum Access
    Replies: 0
    Last Post: 10-26-2009, 12:18 PM
  5. Replies: 4
    Last Post: 04-01-2009, 11:48 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