# Solved: MS Access 2007 OnLoad Event firing twice



## Access07 (Mar 28, 2008)

I have a form that I set the recordsource in the Form Open Event. When this code line executes (Me.Recordsource = strSQL), the program flow skips the following line items in the Open procedure and immediately starts running the Load Event procedure. When the Load Event finishes, the program flow jumps back to the Open Event, finishing the remaining line items and then proceeds to the Load Event (as it should) starting that event all over again.

What may be causing this?


----------



## Access07 (Mar 28, 2008)

Well I used this phenomenon to my advantage. In the form's Open Event I parsed some info and then set an integer variable to 0. Then the me.recordsource = strSQL executes and the program jumps into the Load event. After the Load event finishes, the OnCurrent event fires. I simply bracketed all the OnCurrent code with "If intVar = 1 Then ... End If" so it doesn't execute. Then the program jumps back to the Open Event. I then set the integer variable to 1 and open a recordset clone to find the record I am interested in and set the bookmark (me.bookmark = rs.bookmark) forcing the OnCurrent event to fire again, thus skipping the Load Event. This time intvar is 1 and all the OnCurrent code executes from now on.
From everything I have read your not supposed to be able to navigate records in the Open Event, but I am currently doing it. Hopefully this is purposeful and not a bug and can be exploited further. If it is a bug, well I will be fixing code later on.


----------

