[AccessD] Close a form during the Activate event

Benson, William (GE Global Research, consultant) Benson at ge.com
Mon Dec 5 20:41:28 CST 2011


Sorry, I cannot make my statement about "dangerous to use" very clear at
this time. Essentially, if the form is open and a certain value has
changed (say, for example, a user's privileges have changed from one
class to another) then I do not want them able to see the form that they
had been looking at. So it was on the activate event that this was to be
checked for.

That is not the exact condition, it is a representative example.

To answer Charlotte's question:

"this action cannot be carried out while processing a form or report
event"

Here is a sample of code you can put in a form that is already opened:

Private Sub Form_Activate()
If 1 = 2 Then DoCmd.Close acForm, Me.Name
End Sub


Launch the form, then deactivate it by opening a different form.

Change the code to
If 1 = 1 Then DoCmd.Close acForm, Me.Name

Click back on the first form, you will get this error message.





More information about the AccessD mailing list