Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict read/write access to DB using Windows ID

Status
Not open for further replies.

handsrfull

Technical User
Feb 22, 2008
8
US
My database currently authenticates users using their Windows ID

I have two modules as seen below:

The first is called GetUserName

Code:
Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
   "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
   As Long
   
Function ap_GetUserName() As Variant
   
   Dim strUserName As String
   Dim lngLength As Long
   Dim lngResult As Long

   '-- Set up the buffer
   strUserName = String$(255, 0)
   lngLength = 255

   '-- Make the call
   lngResult = wu_GetUserName(strUserName, lngLength)
   
   '-- Assign the value
   ap_GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)
   
End Function

The second is called ValidateUsers

Code:
Public Function ValidateUser()

'Confirm that the user should be able to enter this database
    Dim db As DAO.Database, rst As DAO.Recordset
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset("SELECT UserName FROM tblUSERS WHERE UserName = """ & UCase(ap_GetUserName) & """;")

    'Check to see if the user name is in the list of valid users
    If rst.EOF Then
        MsgBox "You are not authorized to use this database!" & vbNewLine & _
            "Please contact the Database Administrator for permission.", _
            vbCritical, "No Authorization"
        rst.Close
        Set rst = Nothing
        Set db = Nothing
        Application.Quit
    End If
    
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    
End Function

Is there a way to restrict read/write access to tables/forms based on their Windows IDs?
 
First, have you seen the seven Access forums? That's where the Access lords reside. You'd get more answers there.

Your database shouldn't allow users to get to tables. Users should only see forms. Look at the Startup under Tools.
Based on their windowsID, if that's the way you want to go, why not have different forms appear for that ID? Or if you only want one form, then hide fields based on the ID. Why are you using windowsID anyway?

If you post in the appropriate forum, you'd get other answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top