[AccessD] Setting the Selected property of an unbound listbox is not triggering the AfterUpdate event

Bill Benson bensonforums at gmail.com
Thu Dec 25 19:49:59 CST 2014


You know what? I gave up! I don't know if I was doing anything wrong or not,
but the entire listbox structure for Products and Producers was a holdover
from my standalone form (frmProducts) where the user actually had an
opportunity to select and edit these entities. The current situation is one
where the user has already selected an Order Item Number - which just
requires a lookup to the exact Product (and Producer) that that Order Item
represents... therefore there is no reason to display the Products or the
Producers as a listbox and select the needed value; the user can't make any
other choices in those controls once the Order Item was selected, so I just
changed the controls to unbound text boxes, and set them via DLookups and
the like. Problem solved; mystery remains. Access cracked corn and I don't
care, Access cracked corn and I don't care, Access cracked corn and I don't
care, my problem's gone away. I am sure you've all sung that song a time or
two!

-----Original Message-----
From: Bill Benson [mailto:bensonforums at gmail.com] 
Sent: Thursday, December 25, 2014 7:35 PM
To: 'Access Developers discussion and problem solving'
Subject: Setting the Selected property of an unbound listbox is not
triggering the AfterUpdate event

I have form code running on form1, which has a subform Form2. I am disturbed
that although I wish to set a variety of other controls on subform when the
listindex of that listbox changes, using the AfterUpdate event, it is not
firing. I thought at first it was because I locked it (I want to set it in
code and not allow the user to make changes). However, I specifically unlock
it and still the AfterUpdate event is not firing. That despite the fact that
a very similar listbox's afterupdate on this very same subform is firing,
when I set the Selected property in it.

The code is here. Anyone see anything amiss?


    SQL = "Select FKProductID from OrderProduct where FKOrderID = " &
txtOrderID
    Set R = D.OpenRecordset(SQL)
    If Not R.EOF Then
        R.MoveFirst
        iProductID = R!FKProductID
        Set R = Nothing
        Set Ctrl = Subfrm.Form.Controls("lstProducers")
        iProducerID = DLookup("FKCompanyID", "Product", "ProductID=" &
iProductID)
        Ctrl.Locked = False
        For i = 0 To Ctrl.ListCount - 1
            Ctrl.Selected(i) = False
            If CLng(Ctrl.Column(0, i)) = iProducerID Then
                Ctrl.Selected(i) = True 'The AfterUpdate event for this
listbox does fire
                Ctrl.Locked = True
                Exit For
            End If
        Next
    
        Set Ctrl = Subfrm.Form.Controls("lstProduct")
        Ctrl.Locked = False
        For i = 0 To Ctrl.ListCount - 1
            Ctrl.Selected(i) = False
            If CLng(Ctrl.Column(0, i)) = iProductID Then
                Ctrl.Selected(i) = True 'The AfterUpdate event for this
listbox does not fire even though this value changes from False to True
                Ctrl.Locked = True
                Exit For
            End If
        Next
    
    
    End If




More information about the AccessD mailing list