Open form password (1 Viewer)

Mrkieran23

Registered User.
Local time
Today, 03:03
Joined
Dec 2, 2015
Messages
12
Hello Ladies and Gents

First allow me to say i have not had any training or study in this so i am very limited to what i know. My work places asked me to make something that our production would use as a program,so i took to Access and have done so.

My problem is that i have my program working, and i have areas (forms) which i can access but others cannot so i have put in a password attached to the onOpen event- i want to be able to Add operators and Add deliveries and new parts but i don't want the users to be able to hence the passwords.

I used the below to do this.

Dim pwd As String
pwd = Inputbox("password")
IF pwd = "password" Then
Msgbox "correct"
Else
MsgBox "Incorrect"
DoCmd.Close

End if

End Sub

Well this works fine and does the job but when i Make ACCDE and have it as an executable file only and run it on a computer with Runtime installed the program runs fine but none of the passwords work and allows that user to access all parts.

Could anybody shed any light on this?
 

Grumm

Registered User.
Local time
Today, 12:03
Joined
Oct 9, 2015
Messages
395
I guess you access those protected forms from a button ?
If so I just hide and show it only for the people who needs to see it.
This can be done in the onload of a form :
Code:
Private Sub Form_Load()
    Dim sUser As String
    sUser = Environ("Username")
    If (sUser = "Grumm" Or sUser = "melanie" Or sUser = "roberto" Or sUser = "sophie") Then
        Knop31.Visible = True
    Else
        Knop31.Visible = False
    End If
    If (sUser = "Grumm") Then
        Knop33.Visible = True
        Knop34.Visible = True
        Knop35.Visible = True
        Bijschrift36.Visible = True
    Else
        Knop33.Visible = False
        Knop34.Visible = False
        Knop35.Visible = False
        Bijschrift36.Visible = False
    End If
End Sub

No passwords needed. and it will work in an ACCDE. Hope this helps for you...
 

Mrkieran23

Registered User.
Local time
Today, 03:03
Joined
Dec 2, 2015
Messages
12
Hi Grumm,

This is most interesting, thank you very much, so i would assume that i would need some form of user login for the program?
 

Grumm

Registered User.
Local time
Today, 12:03
Joined
Oct 9, 2015
Messages
395
well the user login is the one from windows.

The "Environ("Username")" returns the username that is actually connected to windows.
You don't need any fancy login form in the access file.
(I use this also for company programs. All users are active-directory users so the username doesn't change and they cannot login to an administrator account.)
I hope this makes sense for you.
 

Mrkieran23

Registered User.
Local time
Today, 03:03
Joined
Dec 2, 2015
Messages
12
That's an amazing idea, i would never have thought to even look at something like that.

So put the code in on the onload event and removing the password one, i have kept it all and replaced grumm with the windows username - Kay

Private Sub Form_Load()
Dim sUser As String
sUser = Environ("Username")
If (sUser = "Kay" Or sUser = "melanie" Or sUser = "roberto" Or sUser = "sophie") Then
Knop31.Visible = True
Else
[Knop31.Visible = False
End If
If (sUser = "Kay") Then
Knop33.Visible = True
Knop34.Visible = True
Knop35.Visible = True
Bijschrift36.Visible = True
Else
Knop33.Visible = False
Knop34.Visible = False
Knop35.Visible = False
Bijschrift36.Visible = False
End If
End Sub


Would this be the correct way to alter this? i appear to be getting a runtime error '424' Object required - i have put it in red font.

I am really sorry, you must read this and think how can this person not know this, i am trying to pick it up myself :(
 
Last edited:

Grumm

Registered User.
Local time
Today, 12:03
Joined
Oct 9, 2015
Messages
395
Well the code i gave is from my project.
I guess your controls have an other name than mine.
You must replace all the "Knop31.Visible = False" to your own buttons.
"Knop31" is the name of the button.
I don't think that way when i read that :) Whatever your skill may be, you are probably better at it than me.

You can also post a little sample database so i can give you an example that makes sense.
 

Mrkieran23

Registered User.
Local time
Today, 03:03
Joined
Dec 2, 2015
Messages
12
:banghead: i don't even know why i didn't think of that.

Of course i need to add my button names, really sorry.

Thank you for this. i will hit the computer on my dinner break and hopefully have it working so i can get it up and running.

Thank you
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:03
Joined
Sep 12, 2006
Messages
15,638
its probably better to have a table of "permitted/master users"

otherwise you have to modify code every time the users change. if you have a table, you just change the data

Code:
 permitted = nz(dlookup("masteruser","usertable","username = " & chr(34) & suser & chr(34)),false)
  
 button.visible = permitted
 

Grumm

Registered User.
Local time
Today, 12:03
Joined
Oct 9, 2015
Messages
395
Well i'm helping people here during my working hours :)
Let us know if you managed to get something working or not. We will be glad to help you out.

I agree with you Dave. My project is also temporarily made in Access.
The background on my project is that the database must be updated 3-4 times a year. And the people using the database don't have always access to the servers here. So I can't split the database and the user-forms. In the future I will make a custom CRM on a website but access was a quick alternative. (that is the reason why i didn't bothered to make fancy stuff and meaningful named buttons)
 
Last edited:

Mrkieran23

Registered User.
Local time
Today, 03:03
Joined
Dec 2, 2015
Messages
12
Hi Grumm,

This worked perfect for me, my program isn't intended to be a large scale thing, only 4 people will be using it to enter in shift data so this method saves me a lot of hassle.

thank you very much.
 

Users who are viewing this thread

Top Bottom