So I am using the following code to the the userid:
Then I am using this to allow access for users to certain forms.
I have a table named "Accesslist" that has 3 columns, users name, users windows id, and office.
How can I add to this code to allow the user to only access members of their own office?
(maintable has all the user information in it for all employees, terrible naming I know!)
Code:
Function GetUserName() As String
Dim LUserName As String
Const lpnLength As Integer = 255
Dim status As Integer
Dim lpName
' Assign the buffer size constant to lpUserName.
LUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
status = WNetGetUser(lpName, LUserName, lpnLength)
' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
LUserName = Left$(LUserName, InStr(LUserName, Chr(0)) - 1)
Else
' An error occurred.
MsgBox "Unable to get the name."
End
End If
GetUserName = LUserName
End Function
Then I am using this to allow access for users to certain forms.
Code:
Public Function autoprotectmain()
If DCount("*", "Accesslist", "WindowsID = '" & GetUserName() & "'") = 0 Then
MsgBox "You are not authorized in this section"
Else
DoCmd.OpenForm "maintable", acNormal, , , acFormEdit, acWindowNormal
End If
End Function
I have a table named "Accesslist" that has 3 columns, users name, users windows id, and office.
How can I add to this code to allow the user to only access members of their own office?
(maintable has all the user information in it for all employees, terrible naming I know!)