Hello everybody!
I have few querstions.Firs t is how do I password protect cmdbuttons?
second is..I have a function that have to return true or false, based on priviledges of an user. i have wrotte this function, but I'm not very god at programming and I would like somebodies oppinion.
here is the function
i am trying to do this- i wannt user to log in the system with username and password, but i don't wannt to use access database security, but i would like to use tables of Users and Tables of Priviledges (Permissions). I would like that my application has a logon form (and it does) and based on the name of the user that has logged in i would like to grant him access to certain cmdbuttons, forms, etc. I have user logon form but it doesnt corespond with the rest of the application. everything is opened and i dont wannt that!
by creating this function i wannted to build in this restrictions, so that i could put some code to every cmdbutton based on username that is loggedon...i would use thi code for cmdbuttons
help please...i have big problems with access code
p.s. sorry for my bad english
I have few querstions.Firs t is how do I password protect cmdbuttons?
second is..I have a function that have to return true or false, based on priviledges of an user. i have wrotte this function, but I'm not very god at programming and I would like somebodies oppinion.
here is the function
Code:
Option Explicit
Public UserID As Long
Public JobPermission As String
Public Function CheckPermission(locUserID As Long, locJobID As Integer) As Boolean
Dim ipomUser As Integer
Dim RS As DAO.Recordset
Dim db As DAO.Database
Dim strSql As String
Dim con As New ADODB.Connection
On Error GoTo ErrorMess
'Set RS = con
strSql = "SELECT Count(JobID) AS job FROM User as o, PermissionUser AS op where op.UserID=o.UserID and o.UserID=" & locJobID
Set db = CurrentDb()
Set RS = db.OpenRecordset(strSql)
'check if there is a permission for user that is log on to application
'RS.Open "SELECT Count(JobID) AS job FROM User as o, PermissionUser AS op where op.UserID=o.UserID and o.UserID=" & locJobID, con, adOpenDynamic, adLockOptimistic
If Not (RS.EOF Or RS.BOF) Then
RS.MoveFirst
ipomUser = RS("Job").Value
Else
MsgBox "Impossible: CheckPermission."
Exit Function
End If
RS.Close
If ipomUser > 0 Then
CheckPermission = True
Else
CheckPermission = False
End If
Exit Function
ErrorMess:
MsgBox "ERROR!"
End Function
by creating this function i wannted to build in this restrictions, so that i could put some code to every cmdbutton based on username that is loggedon...i would use thi code for cmdbuttons
Code:
If Not CheckPermission(UserID, 24) Then
MsgBox "You don't have permission to do this action."
Exit Sub
End If
p.s. sorry for my bad english
Comment