Create a common function, and set the OnOpen event to
=FunctionName()
(Make sure you include the equals sign and parentheses)

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
>I want to set up security with a common routine run every time any form is
> open. What's the best way to have a common routine for the on open event
> of
> every form?
JimS - 08 May 2008 22:29 GMT
Doug, if you don't mind a follow-up... how can I find all forms with no "on
open" event? Is it a property of the form object? Is it available from
allforms, or do I need to open the form in design mode and check the
property? I was planning to write a little routine (so I can practice writing
routines....) to rifle through the allforms collection, and change the "on
open" reference as you suggest....
Thanks again!

Signature
Jim
> Create a common function, and set the OnOpen event to
>
[quoted text clipped - 6 lines]
> > of
> > every form?
Douglas J. Steele - 09 May 2008 12:17 GMT
You need to open the form in design mode and check the property.
Given what I said in the other thread (that you can't use a function after
all), you'll have to set the property to [Event Procedure], and add the sub
to the form's module (take a look at the AddFromString method of the Module
object)

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
> Doug, if you don't mind a follow-up... how can I find all forms with no
> "on
[quoted text clipped - 19 lines]
>> > of
>> > every form?
JimS - 08 May 2008 22:53 GMT
Sorry, Doug, I tried it (on the biggest, slowest-to-open form I have ever
written, of course...), and I became stumped. Here's the routine I wrote...
Public Sub CheckAuthority(Cancel As Integer)
If fnAuthorize(Me.Name) = False Then
Cancel = True
End If
End Sub
...
and the OnOpen event property says: =CheckAuthority()
...
Now, it's not a function. If it should be a function, what does it return?
Is it irrelevant? I'll try again, making it a function and returning a
boolean.

Signature
Jim
> Create a common function, and set the OnOpen event to
>
[quoted text clipped - 6 lines]
> > of
> > every form?
Douglas J. Steele - 09 May 2008 12:14 GMT
Actually, you won't be able to use any value returned by the function. I
forgot that your intent is to prevent the form from opening.
You're going to have to put
Private Sub Form_Open(Cancel As Integer)
Cancel = (fnAuthorize(Me.Name) = False)
End Sub
for all your forms.
Sorry about that.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
> Sorry, Doug, I tried it (on the biggest, slowest-to-open form I have ever
> written, of course...), and I became stumped. Here's the routine I
[quoted text clipped - 27 lines]
>> > of
>> > every form?