Passing Form Name to Public Code

rnutts

Registered User.
Local time
Today, 21:47
Joined
Jun 26, 2007
Messages
110
Hi

I have various forms which are set to Allowedits=False to prevent accidental overwriting of data. Each of these forms has a command button which changes Alloweditsto True. Now my boss wants to password protect these buttons for added security.
I have created a module that will create the inputbox and also check for the correct password, however when using the code below I am returned the error message Me is not allowed. From reading this forum I have gained the understanding that Me is specific to the current form and that I need to pass the forms name to the public code.
This is my first time with this passing of variables and I am clueless, so I would really appreciate some help and advice.

Public Sub passwordcheck_click()
Dim Message, Title, MyValue
Message="Enter Password" 'Set prompt.
Title="Password Check" 'Set Title.
'Display message,title
MyValue=InputBox(Message,Title)
If MyValue=241055 then
Me. Allowedits=True
End If
End Sub
 
Have you tried using the Active.Form property of Access?
 
Create a Function in a standard module (not form module) like this:
Code:
Public Bunction PasswordCheck() As Boolean
Dim Message, Title, MyValue
   Message="Enter Password" 'Set prompt.
   Title="Password Check" 'Set Title.
   'Display message,title
      MyValue=InputBox(Message,Title)
          If MyValue=241055 then
              PasswordCheck = True
          Else
              PasswordCheck = False
         End If
End Function

Then in your form, call the sub like this:
Code:
        Me.AllowEdits = PasswordCheck(Me.Name)
 
Last edited:
Bob

Have tried both of your answers
Answer 1 caused a compile error with the 1st line of the module code with the word As highlighted by Access

Answer 2 causes a compile error with the code in the form saying I have the wrong number arguments

any thoughts
 
Bob

Have tried both of your answers
Answer 1 caused a compile error with the 1st line of the module code with the word As highlighted by Access

Answer 2 causes a compile error with the code in the form saying I have the wrong number arguments

any thoughts

For the first line, I had just copied what you had put in the first post, but it should be:
Code:
Dim Message As String
Dim Title As String
Dim MyValue As String
Now, you can put that all on one line, but I don't usually like to as it makes it easier to see what you are declaring if they are all on separate lines.

The second one that is causing a problem is that I removed the part that referred to the name of the form in the function as it really wasn't necessary. So, change:
Code:
Me.AllowEdits = PasswordCheck(Me.Name)
To This:
Code:
Me.AllowEdits = PasswordCheck
 
Do you really want to hard code the password into the program?
 
Thanks, removing the (Me.Name) worked

Enjoy the rest of your Sunday
 
At the minute I want to hard code the password, hence the module so that If I want to change the password, I only change in one place not in every form.
I have looked at the security settings for users but at the minute cannot think of a way around my problem.
My original problem is that I want to prevent accidental changing of records by users who are viewing or entering data hence Me.Allowedits=False.
But there is also a need to edit data on purpose for client address changes etc hence the command button which changes Me.Allowedits=True.
So users need to be data entry as well as read only if you see what I mean.
 
Do you really want to hard code the password into the program?

RG's got a point. It would make things much easier if you store the password in, say a hidden table. Then, if you need to change it, it is just a matter of going into the table and making the change.

For a database I'm currently working on, we have a bunch of non-technical users who just need to see certain parts of the database and I created a little program, with code from the Microsoft website, which creates a number from an input password. We just have about 4 department level passwords that we need so I've created it so that the group name and encrypted password is stored in a text file and when someone needs to open something that is restricted by group, I have the user select their group, type in their password, and it passes through that encryption function to encrypt it and then I read the text file values to compare the value in it for that group with the value that they have entered and if it matches they get to access the item in question.

So, if we need to change the group passwords for them, we can do it easily and send them the new text file to put in the directory with the mdb file. It makes maintenance easy to do without having to have direct access to their system.

That's how I've done it on this one, but there are other methods as well.
 

Users who are viewing this thread

Back
Top Bottom