Login form that goes by PC login (1 Viewer)

oxicottin

Just pecking away....
Local time
Today, 01:49
Joined
Jun 26, 2007
Messages
562
Hello, I remember seeing an example of a login form that went by the persons login name. I wanted to have a login that if your name was lets say Access Lvl 2 then you could only do certain things. I'm just curious if there was an example?

Thanks
 

theDBguy

I’m here to help
Local time
Yesterday, 22:49
Joined
Oct 29, 2018
Messages
10,816
Hi. Yes, there should be an example of that in the Sample Databases forum. Sorry, can't give you a link right now.

Sent from phone...
 

Micron

AWF VIP
Local time
Today, 01:49
Joined
Oct 20, 2018
Messages
3,202
If you're going to use the Windows user name as a login, do you really need a form? Why not like this -
- someone opens the db
- you get their login id (either Temp Vars or fOsUsername function) and DLookup the profile level via user name
- if not found, message "Sorry bud, you're not a registered user" or similar and close db
- if found, their level is now known

What you do from there with respect to checking that level when opening things or even allowing someone to see a control is a matter of preference.
I prefer to create a user object so that I can assign any property that I think is needed; e.g. usrLevel, FName, LName, emplNo etc. and retrieve that any time by referring to dbUser.
 

theDBguy

I’m here to help
Local time
Yesterday, 22:49
Joined
Oct 29, 2018
Messages
10,816
Hi. Yes, there should be an example of that in the Sample Databases forum. Sorry, can't give you a link right now.

Sent from phone...
Okay, back in front of a computer now... Here's a link for you. Hope it helps...

 

oxicottin

Just pecking away....
Local time
Today, 01:49
Joined
Jun 26, 2007
Messages
562
Thanks, the info was very helpful....
 

isladogs

CID Moderator
Staff member
Local time
Today, 06:49
Joined
Jan 14, 2017
Messages
13,433
Hi
As the link is to the sample database I updated from the original by David Crake, let me know if you have any questions or suggestions about the app.
 

oxicottin

Just pecking away....
Local time
Today, 01:49
Joined
Jun 26, 2007
Messages
562
Ok, I been messing with this login and im not sure how to go about allowing all the users that I dont have listed in my table. Here is what I wanted to do, I wanted the login to be hidden like it is on my example and if:

  1. If your fOSUserLoginName is in the table and your UserSecurityType is a 2 - SuperUser then enable certain buttons.
  2. If your fOSUserLoginName is in the table and your UserSecurityType is a 3 - Administrator then enable all buttons.
  3. But if your fOSUserLoginName isnt in the table which makes you a 1 - StandardUser then disable certain buttons.
I cant figure out how to setup #3 in the list above on my form. Thanks!
 

Attachments

zeroaccess

Active member
Local time
Today, 00:49
Joined
Jan 30, 2020
Messages
586
I simply make it so if it doesn't find you in the table, you can't proceed to the Home screen. Instead, you'll get a message box on clicking Login.
 

zeroaccess

Active member
Local time
Today, 00:49
Joined
Jan 30, 2020
Messages
586
This might give you ideas:

SQL:
Private Sub Form_Load()
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    DoCmd.ApplyFilter , "[LAN ID]='" & fOSUserName & "'"
    Me.cmdUnseen.SetFocus
End Sub
SQL:
Private Sub cmdLogin_Click()
On Error GoTo cmdLogin_Click_Err

    If (fOSUserName() = [LAN ID]) Then
        TempVars.Add "CurrentUserID", [User ID].Value
        Me.Visible = False
        DoCmd.OpenForm "frmHome", acNormal, "", "", , acNormal
        Exit Sub
    Else
        Beep
        MsgBox "Ask your Administrator for access to this system.", vbOKOnly, ""
    End If


cmdLogin_Click_Exit:
    Exit Sub

cmdLogin_Click_Err:
    MsgBox Error$
    Resume cmdLogin_Click_Exit

End Sub
LAN ID is a field in my Users table, which I set as the recordsource for the form. cmdUnseen is just a transparent button that I use to move the focus to.

I haven't done program-wide access changes based on privilege. Instead, I just use privilege levels at the time I need them, usually enabling/disabling something on form load or current. That could change, but it's not a high priority at the moment.
 
Last edited:

oxicottin

Just pecking away....
Local time
Today, 01:49
Joined
Jun 26, 2007
Messages
562
Thanks again fellas I got it working....
 

isladogs

CID Moderator
Staff member
Local time
Today, 06:49
Joined
Jan 14, 2017
Messages
13,433
Congratulations. Sorry I didn't reply earlier but the site had been unavailable since yesterday afternoon.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom