Reputation: 1944
Two forms in an A2007 app have stopped triggering their OnLoad events after the OnOpen event. The events have been working for years, and I can't determine why the OnLoad event isn't running now.
Instead, clicking on any control on the forms triggers the OnLoad event - including the window's Close button.
The forms are unbound, with subforms that are filtered by a common function called in the OnLoad event. There are many other forms like this, which are still working OK.
I have checked that the event is still linked to the code by clicking on the ellipsis in Properties next to the event ([Event Procedure]), which takes me correctly to the code.
Have decompiled/recompiled. Checked References. Imported to a new db.
Tried adding a RecordSource (SELECT anyField FROM anyTable LIMIT 1), which didn't work, and then I found a work-around, by adding Me.RecordSource=Me.RecordSource as the last line in the OnOpen event - which does then trigger the OnLoad event.
This is the first time in almost 20 yrs of Access development that I've come across this, and as I get very nervous whenever Access 'misbehaves', I'd really like to find the problem. Any suggestions would be most welcome!
Upvotes: 4
Views: 5461
Reputation: 57
Had a problem with the same symptoms in MS Access 2016. But Adding "Me.RecordSource = Me.RecordSource" did not help me, it made it worse.
After successlessly trying the other suggested solutions with building the form completely new from scratch, I built it up again and after every step checking whether it still functioned.
It came out that access cannot handle calling a function (with return value) as default for an optional parameter. (This applicates to all procedures defined in the forms module)
As I am fairly new to VBA and Access development this may be a beginners mistake, but maybe it helps someone to post it here.
Upvotes: 0
Reputation: 145
I had the same problem in a form I was developing however I didn't have any code in the Open event but suddenly my Load event code stopped running when opening the form.
Adding the "Me.RecordSource = Me.RecordSource" code in the Open event then resolved the issue?
I know this isn't an answer but it does prove that Max's code couldn't have been hung up in the Open event.
The only other significant information is that I am developing this on two PCs, one with Access 2007 and one with 2010 but I don't recall if the Load event stopped running after I moved the code back to the Access 2007 PC.
Upvotes: 1