Hi, I'm trying to use the users network login name as a rudimentary security method so that people can only edit record in a database for which their name appears in one of the fields, see this link for the discussion on this http://www.access-programmers.co.uk/forums/showthread.php?t=154562
I have this working but now want to add an extra layer that if the person's position is listed as "Administrator" in the [Position] field of the [Users] table then they can edit any of the records. I am trying to do this using Dlookup with the code below.
The Dlookup command however isn't working and comes up with the error:
Runtime Error '3705'
Syntax error in string in querry expression '[Login]='CRERAR_R'
The code behing ap_GetuserName is
I am assuming it soemthing to do with the possition of the quote marks in teh Dlookup but have tried every combination I can think of. Can anyone help?
Also. If I were to use the standard access secruity to give administrtion rights to certain people would this overwrite the AllowEdits command? My thinking is that the AllowEdits = falsue would override anything else so that is why I have not tried this yet.
Finally. Is there anyway to extract the value from a hidden or disabled field in a form as although the code works by enabling and then disabling the login field I would really prefer to just have it hidden as it would be preferable for all users not to be able to see everyone elses login name for obvious resons.
Thanks
I have this working but now want to add an extra layer that if the person's position is listed as "Administrator" in the [Position] field of the [Users] table then they can edit any of the records. I am trying to do this using Dlookup with the code below.
Code:
Login.Enabled = True
Login.SetFocus
stAdminLogon = ap_GetUserName()
vAdminLogon = DLookup("[Position]", "[Users]", "[Login]='" & stAdminLogon & "'")
If Me.Login <> stAdminLogon And vAdminLogon <> "Administrator" Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
Me.Text6.Enabled = False
Position.SetFocus
Login.Enabled = False
The Dlookup command however isn't working and comes up with the error:
Runtime Error '3705'
Syntax error in string in querry expression '[Login]='CRERAR_R'
The code behing ap_GetuserName is
Code:
Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Function ap_GetUserName() As Variant
'Returns the network login name
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
If lngResult <> 0 Then
ap_GetUserName = RTrim(strUserName)
Else
ap_GetUserName = ""
End If
End Function
I am assuming it soemthing to do with the possition of the quote marks in teh Dlookup but have tried every combination I can think of. Can anyone help?
Also. If I were to use the standard access secruity to give administrtion rights to certain people would this overwrite the AllowEdits command? My thinking is that the AllowEdits = falsue would override anything else so that is why I have not tried this yet.
Finally. Is there anyway to extract the value from a hidden or disabled field in a form as although the code works by enabling and then disabling the login field I would really prefer to just have it hidden as it would be preferable for all users not to be able to see everyone elses login name for obvious resons.
Thanks
Last edited: