help needed with security alternative (1 Viewer)

kdt

Registered User.
Local time
Today, 18:34
Joined
Apr 5, 2006
Messages
48
Hi

I have a custom login screen created for my database and a table with access levels for different users. I am trying to assign user permissions so that certain buttons on the switchboard are visible/not visible dependent on the user security level. As the login screen and the switchboard are on seperate forms, is there any way I can do this??

I've been pulling my hair out since last night so any help at all would be appreaciated

cheers
 

MaliciousMike

Registered User.
Local time
Today, 18:34
Joined
May 24, 2006
Messages
118
kdt said:
Hi

I have a custom login screen created for my database and a table with access levels for different users. I am trying to assign user permissions so that certain buttons on the switchboard are visible/not visible dependent on the user security level. As the login screen and the switchboard are on seperate forms, is there any way I can do this??

I've been pulling my hair out since last night so any help at all would be appreaciated

cheers

one option is to do an if statement and making the button visible if the level is correct.

If Level > 1 then
cmdBetterThanYou.Visible = true
End If

Otherwise, some message box saying "you're not important enough, go away" would suffice.
 

kdt

Registered User.
Local time
Today, 18:34
Joined
Apr 5, 2006
Messages
48
thanks for the quick reply, but that is just the problem, how does access know who the user (and therefore the access level) is after the login screen is closed? I tried using an if statement on the login form but that didnt work and using a DLookup on the Switchboard, but that just returned the first value in the table ?? I'm really confused now!
 

Jibbadiah

James
Local time
Tomorrow, 03:34
Joined
May 19, 2005
Messages
282
Create a global module
In this module add the following:
Public gstrUser As String

Then in the login screen assign the user value to the global string
gstrUser = me.txtLogin.value

This should make it available for use after logging in.
 

MaliciousMike

Registered User.
Local time
Today, 18:34
Joined
May 24, 2006
Messages
118
kdt said:
thanks for the quick reply, but that is just the problem, how does access know who the user (and therefore the access level) is after the login screen is closed? I tried using an if statement on the login form but that didnt work and using a DLookup on the Switchboard, but that just returned the first value in the table ?? I'm really confused now!

my bad.

the other option is to use open args on every form
 

Fear Naught

Kevin
Local time
Today, 18:34
Joined
Mar 2, 2006
Messages
229
I have buildt my own login form for a small system we use in the office. As explained above I have a module with Global Variables (not Public). At the login stage I assign values to these variables such as the user name, user id, their status and whether they are admin users. The code I use to this is behind the login button on the form and is reproduced below.

There is other code that checked whter the user name entered is valid and also checks the number of failed attempts at logging in. (the system quits after 3 failed attempts). There is alo code that adds successful logins to a table so that I know who is currently logged in and who and when people did login.

The system is still being developed so there may be some redundant code but hey nobody is perfect :)

I hope this helps.

Code:
Private Sub ButLogin_Click()
    Dim strFormLogin As String
    Dim strFormPassword As String
    Dim strSQL As String
    Dim strFormName As String
    
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    strFormLogin = Nz(Me.txtUserName, " ")
    strFormPassword = Nz(Me.txtPassword, 0)
    strFormName = "frmMainmenu"
    
    strSQL = "SELECT UserNameID, Name, Password,Admin,statusid,isuser " & _
            "FROM tblUsers " & _
            "WHERE Name = '" & Forms!frmLogin!txtUserName & "'  "
    
    Set rs = CurrentDb.OpenRecordset(strSQL)
    
    If rs.RecordCount = 0 Then
        gintLoginAttempts = gintLoginAttempts + 1
        If gintLoginAttempts = 3 Then
            MsgBox "You have had 3 unsuccessful login attempts " & vbCr & vbCr _
                & "The application will now close.", vbCritical, "Failed Login"
            DoCmd.Close
            Exit Sub
        End If
        MsgBox "Your Login name is not recognised", vbExclamation, "Unknown User Name"
        Me.txtUserName = ""
        Me.txtUserName.SetFocus
        Me.ButExit.Default = False
        Exit Sub
    End If
    
    If Not rs!IsUser Then
        MsgBox "Your UserName (" & rs!Name & ") has been made inactive. " & vbCr & vbCr & "Contact the System Administrator." & vbCr & vbCr & "The system will now close down.", vbCritical, "Inactive User"
        DoCmd.Close
        Exit Sub
    End If
    
    If rs!Password = strFormPassword Then
        
        gstrUserName = rs!Name
        gintUserID = rs!UserNameID
        gblnAdmin = rs!Admin
        gintStatus = rs!StatusID
        
        Set rs2 = CurrentDb.OpenRecordset("tblLogins", dbOpenDynaset)
    
        With rs2
            .AddNew
            !UserNameID = gintUserID
            !Timein = Now()
            !Status = "In"
            .Update
        End With
        
        DoCmd.Close
        DoCmd.OpenForm strFormName
        
    Else
        ggintLoginAttempts = ggintLoginAttempts + 1
        If ggintLoginAttempts = 3 Then
            MsgBox "You have had 3 unsuccessful login attempts " & vbCr & vbCr _
                & "The application will now close.", vbCritical, "Failed Login"
            DoCmd.Close
            Exit Sub
        End If
        MsgBox "You entered and incorrect password", vbExclamation, "Incorrect Password"
        Me.txtPassword = ""
        Me.txtPassword.SetFocus
        Exit Sub
    End If
    
 rs.Close
 rs2.Close
End Sub
 

MStef

Registered User.
Local time
Today, 18:34
Joined
Oct 28, 2004
Messages
2,251
Hello kdt!

Look at "DemoLoginPasswordA2000.mdb", i think ti can help you.
Open Form1 and try.
 

Attachments

  • DemoLoginPasswordA2000.zip
    11.2 KB · Views: 132

kdt

Registered User.
Local time
Today, 18:34
Joined
Apr 5, 2006
Messages
48
Wow! you guys are superb! thanks a lot for all the good answers, I have been trying some of the code and there's definately a lot of good stuff here. I'm still pretty rubbish at vb but I'm getting there :)

Thanks again!
 

Fear Naught

Kevin
Local time
Today, 18:34
Joined
Mar 2, 2006
Messages
229
kdt said:
Wow! you guys are superb! thanks a lot for all the good answers, I have been trying some of the code and there's definately a lot of good stuff here. I'm still pretty rubbish at vb but I'm getting there :)

Thanks again!

A pleasure to help. There is always lots to learn in Access and VB. :)
 

Users who are viewing this thread

Top Bottom