koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
Can someone please explain EXACTLY how this function work?
The reason I want to know is that I have a split database using in the office.
We have 3 types of users:
Power User: No restrictions
Laptop User: Limited Restrictions
Desktop User: Very Limited Restrictions
A desktop user is unable to right click or add files to thier desktops and cannot access the C drive. The laptop users can.
The problem I am having is that only the laptop users are able to log into the database.
This is the code I got from the Intenet to check the user name.
This is the code I created to check the user name added to the database against the network user name.
setrst Function:
The ckUserLoggingin function is called from an AutoExec macro.
The latop users were able to access the database but when a desktop user tries, they get an error in a message box:
Title:
Action Failed
Macro Name:
AutoExec
Condition:
True
ActionName:
RunCode
Arguments:
ckUserLoggingin
Can anyone also tell me if the restrictions would cause this problem because when I had initially researched the apiGetUserName function, from my limited knowledge, I understood it is supposed to be using LDAP to query the domain controller. If that is the case, then I do not think the restrictions on the machines would make a difference.
Please help!!!! I appreciate any feedback.
Thanks.
The reason I want to know is that I have a split database using in the office.
We have 3 types of users:
Power User: No restrictions
Laptop User: Limited Restrictions
Desktop User: Very Limited Restrictions
A desktop user is unable to right click or add files to thier desktops and cannot access the C drive. The laptop users can.
The problem I am having is that only the laptop users are able to log into the database.
This is the code I got from the Intenet to check the user name.
Code:
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
Function getempstatus() As String
getempstatus = DLookup("UserLevel", "tblUsers", "UserName = '" & fOSUserName() & "'")
End Function
Function fOSMachineName() As String
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function
This is the code I created to check the user name added to the database against the network user name.
Code:
Public Function ckUserLoggingin()
Call setrst
rst.Open "select * from tblUsers"
If rst.RecordCount >= 1 Then
rst.MoveFirst
For i = 1 To rst.RecordCount
If fOSUserName() = rst!UserName Then
If rst!Active = "Yes" Then
Call setrst1
rst1.Open "select * from tblEmpLogin where rec =1"
rst1!empstatus = getempstatus()
rst1!EmpName = fOSUserName()
rst1.update
rst1.Close
Set rst1 = Nothing
End If
DoCmd.RunMacro "Startup"
Exit Function
End If
rst.MoveNext
Next
i = MsgBox("Access Denied! You do not have sufficient privilidges to open this file. Please check with the system Administrator. Quitting...", vbCritical, "Access Denied")
DoCmd.Quit
End If
End Function
setrst Function:
Code:
Private Sub setrst()
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.CursorLocation = adUseClient
End Sub
The ckUserLoggingin function is called from an AutoExec macro.
The latop users were able to access the database but when a desktop user tries, they get an error in a message box:
Title:
Action Failed
Macro Name:
AutoExec
Condition:
True
ActionName:
RunCode
Arguments:
ckUserLoggingin
Can anyone also tell me if the restrictions would cause this problem because when I had initially researched the apiGetUserName function, from my limited knowledge, I understood it is supposed to be using LDAP to query the domain controller. If that is the case, then I do not think the restrictions on the machines would make a difference.
Please help!!!! I appreciate any feedback.
Thanks.