passing form name to module

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

passing form name to module

Post by BobSullivan »

I would like to perform a generic test of user id for all forms in a database, so that only certain people have editing rights. Here's what I have:

In the On Load event of the form, I have

Code: Select all

TheForm=Me.Name
module1.Security
In module1 I have the following code:

Code: Select all

Public TheForm as string
Sub Security ()
If environ("UserName") = "Bob" then
TheForm.AllowEdits = True
Else: TheForm.AllowEdits = False
End If
I'm getting an "Invalid Qualifer" error. I'm thinking I don't have the form Name variable dimensioned correctly. How should I dimension it?
Cordially,

Bob Sullivan
Elverson, PA

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: passing form name to module

Post by HansV »

A string is not the same as a form.

Option 1:

Change the declaration of TheForm to

Public TheForm As Form

and change the line

TheForm = Me.Name

to

Set TheForm = Me

Option 2:

Leave the above lines unchanged, but change both occurrences of TheForm.AllowEdits to Forms(TheForm).AllowEdits
Best wishes,
Hans

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

Re: passing form name to module

Post by BobSullivan »

:clapping: Thanks! I used the second option.
Cordially,

Bob Sullivan
Elverson, PA