Common form.open Routine

  • Thread starter Thread starter JimS
  • Start date Start date
J

JimS

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?
 
Create a common function, and set the OnOpen event to

=FunctionName()

(Make sure you include the equals sign and parentheses)
 
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!
 
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.
 
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.
 
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)
 
Back
Top