By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,454 Members | 2,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,454 IT Pros & Developers. It's quick & easy.

User Security

P: 3
Hello everybody!
I have few querstions.First 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
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Public UserID As Long
  3. Public JobPermission As String
  4.  
  5. Public Function CheckPermission(locUserID As Long, locJobID As Integer) As Boolean
  6.     Dim ipomUser As Integer
  7.     Dim RS As DAO.Recordset
  8.     Dim db As DAO.Database
  9.     Dim strSql As String
  10.     Dim con As New ADODB.Connection
  11.  
  12.     On Error GoTo ErrorMess
  13.     'Set RS = con
  14.     strSql = "SELECT Count(JobID) AS job FROM User as o, PermissionUser AS op where op.UserID=o.UserID and o.UserID=" & locJobID
  15.     Set db = CurrentDb()
  16.     Set RS = db.OpenRecordset(strSql)
  17.  
  18.     'check if there is a permission for user that is log on to application
  19.  
  20.     '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
  21.  
  22.     If Not (RS.EOF Or RS.BOF) Then
  23.         RS.MoveFirst
  24.         ipomUser = RS("Job").Value
  25.     Else
  26.         MsgBox "Impossible: CheckPermission."
  27.         Exit Function
  28.     End If
  29.     RS.Close
  30.  
  31.     If ipomUser > 0 Then
  32.         CheckPermission = True
  33.     Else
  34.         CheckPermission = False
  35.     End If
  36.  
  37. Exit Function
  38.  
  39. ErrorMess:
  40.     MsgBox "ERROR!"
  41.  
  42. End 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
Expand|Select|Wrap|Line Numbers
  1. If Not CheckPermission(UserID, 24) Then
  2.     MsgBox "You don't have permission to do this action."
  3.     Exit Sub
  4. End If
help please...i have big problems with access code

p.s. sorry for my bad english
Dec 17 '07 #1
Share this Question
Share on Google+
1 Reply


NeoPa
Expert Mod 15k+
P: 31,186
It's hard to know how to answer this one.
Your code tells me very little and your English is understandably poor.
I can't even tell how you're expecting this to work.
Perhaps some indication of the sort of data you're working with may assist.
Please post the metadata for your tables [User] & [PermissionUser].

Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Please try to post it correctly as per the example. This is not language based so there would be no good excuse for failing to provide this data correctly. If there is anything about this you don't understand just ask.
Dec 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.