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

Bill Benson bensonforums at gmail.com
Thu Dec 25 18:34:43 CST 2014


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