Return to Main form from second form - Event wont fire (1 Viewer)

Rx_

Nothing In Moderation
Local time
Today, 09:50
Joined
Oct 22, 2009
Messages
2,803
On a Master Form with a listbox (lst_id_wells) - if the value of a well is passed into a custom function ROW_Required_For_Well - it turns a colored box on or off. This just gives a visable indicator to the user as they scroll down a list box - if that Well has a ROW or not.

This form stays open, another form opens. It displays a list of ROW. If a user chooses a different ROW, it updates that form's ROW and it updates the Master Form's list box ROW (the list_id_Wells value is correctly highlighted).

Problem - The code below won't fire in any event that on the Master Form. So, when closing the secondary form, the Master Form list box has a Well selected that won't hight-light the ROW.
Tried the Master Forms's Got Focus, Resize, and so on.

The secondary form changes the Master Form lst_Id_Wells value with the code:
Forms![home_2]![lst_id_wells] = Me.ID_Wells
The code above highlights the correct item in the listbox,
But, changing the value from another form does not trigger the AfterUpdate (or any other event) to run the function.

Code:
Private Sub lst_id_wells_AfterUpdate()
10    On Error Resume Next
20    If Not IsNull(Me!lst_id_wells) Then
30            If ROW_Required_For_Well(Me!lst_id_wells) Then
40                Me.BoxRowIndicator.Visible = True
50            Else
60                Me.BoxRowIndicator.Visible = False
70            End If
80    End If
 

Attachments

  • Function Does not fire if listbox value changed remotely.png
    Function Does not fire if listbox value changed remotely.png
    60.5 KB · Views: 130
Last edited:

RuralGuy

AWF VIP
Local time
Today, 09:50
Joined
Jul 2, 2005
Messages
13,826
Events do not fire unless the USER makes the change. Programatically changing something does not fire any events. If you want them to execute then you need to call them in code.
 

Rx_

Nothing In Moderation
Local time
Today, 09:50
Joined
Oct 22, 2009
Messages
2,803
Thanks. Yes, that is the exact problem.
The solution is to put this code in the second form to call the even in the Master form:

Call Form_Home_2.lst_id_wells_AfterUpdate
i.e. Form_Name.ProcedureName
Also:
In the list object, the event with the function that changes the boxes in the Master form must be changed from Private to Public

Public Sub lst_id_wells_AfterUpdate()
' the code that calls functions to update the boxes with user interaction was here.

When the second form updates the primary key (i.e. list box) on the Master form, it did not call the event. Because events are fired by users actions.
By adding the code above (and makeing the event on the Master form) public, the VBA code calls the event.

This is probably restating the obvious. I posted this at the end of a 10 hour day, the solution seemed so simple this morning.
 

Users who are viewing this thread

Top Bottom