Reply to post #19[
QUOTE=Edgar;508165]...
Basically, what I'm seeing is not a bug, it is something expected (so far). If I step through the code, it does not fire events. But if I interact with the form, the events work perfectly.
Check the database attached[/QUOTE]
Okay, I made a minor change to your database. Added a simple variable to test, and your database presents with the same problem as my big one.
Here's all the code for Form2 with changes in bold:
Code:
Option Compare Database
Option Explicit
Dim TestVariable As Variant
Private Sub Form_Load()
TestVariable = Me.hwnd
Debug.Print "Loading form variable", TestVariable
End Sub
Private Sub btnCheckVariable_Click()
MsgBox Me.hwnd
End Sub
Private Sub Form_Close()
'Stop
RemoveOneFromCollection Me.hwnd
Debug.Print "closing " & Me.hwnd
' Insert some stuff
InsertIntoTable Me.hwnd
' Populate listbox
CheckCollection
If TestVariable <> Me.hwnd Then Debug.Print "Bad variable!", "." & TestVariable & ".", Me.hwnd
End Sub
The TestVariable is getting reset before the form closes, even without a lot of "extra complicated code" that mine has.
Here are the immediate window results from running Form2 once from Form 1 (highlighted on green) and then a second time from the navigation pane (highlighted in orange).
See how the second run doesn't show a variable clearing error?
Or do you expect two different ways of running the same form to present with different results when closing? I sure don't. That's a big fat bug to me and a two week pain-in-the-arse (just one of the dozens I've had with Access). But maybe it doesn't exist in your version. I am using Access 2021 and it's there clear as day. So, after reviewing your smaller demo, we've confirmed exactly what I said in post #1.
That's why I went with the second approach in my demo db. It has its own inconsistent bugs in Access.
Cheers