G
Guest
Hi All...I am desining an application where I have several forms..say about
15. From the Main Menu some of the forms can be accessed. I have buttons to
access those forms on click events. Some of the forms also contain subforms
and tab controls. Now, on each forms including the main form I want the
system to display certain things based on user access level. I know how to do
this by having detect the user and the access level on each form. To cut the
redundancy, I want to create a module and on each form I want to call the
function that will return me the access level. Now, this I am not sure how to
do it from module level and I am looking from you to assist me. Any help you
can provide me would be greatly appreciated. Please see below the code I
tried to use in a module. Just an FYI, I am not using access security. I am
detecting user name from Library and I have table that contains the same
username and accesslevel. This is to ensure end user doesn't have to remember
one more userID and password, something more towards single sign on kind of
thing.
Option Compare Database
Private Declare Function getUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public txtUserName As String
Public Function getUser() As String
Dim strBuffer As String
Dim lngLen As Long, lngReturn As Long
strBuffer = String$(15, " ")
lngLen = 15
lngReturn = getUserName(strBuffer, lngLen)
If lngReturn Then
getUser = Left(strBuffer, lngLen - 1)
Else
getUser = ""
End If
End Function
Public Function getAccess(access) As String
Dim strSql
Dim mydb
Dim myrecset
Dim access
strSql = "select tblUserAccessLevel from tblUser where tblUserName = " &
"'" & getUser & "'"
Set mydb = CurrentDb
Set myrecset = mydb.openrecordset(strSql)
access = myrecset.tblUserAccessLevel
End Function
15. From the Main Menu some of the forms can be accessed. I have buttons to
access those forms on click events. Some of the forms also contain subforms
and tab controls. Now, on each forms including the main form I want the
system to display certain things based on user access level. I know how to do
this by having detect the user and the access level on each form. To cut the
redundancy, I want to create a module and on each form I want to call the
function that will return me the access level. Now, this I am not sure how to
do it from module level and I am looking from you to assist me. Any help you
can provide me would be greatly appreciated. Please see below the code I
tried to use in a module. Just an FYI, I am not using access security. I am
detecting user name from Library and I have table that contains the same
username and accesslevel. This is to ensure end user doesn't have to remember
one more userID and password, something more towards single sign on kind of
thing.
Option Compare Database
Private Declare Function getUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public txtUserName As String
Public Function getUser() As String
Dim strBuffer As String
Dim lngLen As Long, lngReturn As Long
strBuffer = String$(15, " ")
lngLen = 15
lngReturn = getUserName(strBuffer, lngLen)
If lngReturn Then
getUser = Left(strBuffer, lngLen - 1)
Else
getUser = ""
End If
End Function
Public Function getAccess(access) As String
Dim strSql
Dim mydb
Dim myrecset
Dim access
strSql = "select tblUserAccessLevel from tblUser where tblUserName = " &
"'" & getUser & "'"
Set mydb = CurrentDb
Set myrecset = mydb.openrecordset(strSql)
access = myrecset.tblUserAccessLevel
End Function