I have done this before in a different database, and it works fine. However, when I set it up in a second database, I am getting errors. Here is the code in the On Load event for the form:
'**Begin Code**
Private Sub Form_Load()
'find out if the user has access
Dim chkUser As Recordset
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
'Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
'set if there is a user
Set chkUser = CurrentDb.OpenRecordset("Select * FROM Security WHERE Name = '" & UserName & "'"
If chkUser.RecordCount = 1 Then
Check53.Locked = False
Check43.Locked = False
Else
Check53.Locked = True
Check43.Locked = True
End If
End Sub
'**End Code**
I also included the following lines of code in the general declarations:
'**Begin Code**
Option Compare Database
Option Explicit
' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
'**End Code**
When the form is opened, I get a compile error that highlights the 'Chr' function and says something to the effect of "Project or Library not found.' Any ideas are greatly appreciated. As I stated earlier, I took the code from a different database that works correctly, so I don't understand why this one is not working.
Thanks,
Jon
'**Begin Code**
Private Sub Form_Load()
'find out if the user has access
Dim chkUser As Recordset
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
'Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
'set if there is a user
Set chkUser = CurrentDb.OpenRecordset("Select * FROM Security WHERE Name = '" & UserName & "'"
If chkUser.RecordCount = 1 Then
Check53.Locked = False
Check43.Locked = False
Else
Check53.Locked = True
Check43.Locked = True
End If
End Sub
'**End Code**
I also included the following lines of code in the general declarations:
'**Begin Code**
Option Compare Database
Option Explicit
' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
'**End Code**
When the form is opened, I get a compile error that highlights the 'Chr' function and says something to the effect of "Project or Library not found.' Any ideas are greatly appreciated. As I stated earlier, I took the code from a different database that works correctly, so I don't understand why this one is not working.
Thanks,
Jon