Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The OnActivate event on a form executes twice and appears out of order

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
I have an Access 2007 form (Form A) with a button that executes a macro that opens another form (Form B). In the OnActivate property of Form B, I have an event procedure that executes a function I created in a new object module. The function includes code that sets the active form's recordset type to snapshot (Screen.ActiveForm.RecordsetType = conSnapshot). The problem is that this OnActivate event procedure code gets executed twice. I have displayed the name of the active form in the function and the first time it executes it displays Form A. The second time it executes it displays Form B. According to Microsoft, the OnActivate event is not supposed to fire until Form B has become the active form. So, 1) why does the function execute twice and 2) why doesn't the active form become Form B until the second time? Even if changing the recordset type triggers the re-activation of the form, still the first time it executes it seems to me the active form should be Form B, not Form A. Hope this is all clear. This matter has me nonplussed. Any help will be much appreciated!
PS: I know there is another old thread with essentially the same question, but there was no real answer.
 
Since you have "displayed the name of the active form in the function" it sounds like perhaps the function is not just being called from the OnActivate event.

I'd put a breakpoint into the function, and then examine the call stack.
 
I found out by further investigation that the OnActivate event occurs just BEFORE the form becomes the active form. Thus, Form A was still the active form when setting the Recordset Type. Here is how I solved the issue: I created a procedure with an argument that is the name of the form I want to open and for which I want to set the Recordset Type. In the OnOpen statement, I call the procedure. The called procedure is --> UserPermissions(sFormName) and it receives the form name from the calling sub. Then, I set the Recordset Type within the UserPermissions procedure. So far, it is working the way I want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top