E
Emma
My "main switchboard" screen calls a function to find out
the user's network name. (I got the code from a MS
support site.) It works fine, but I need to verify that
the user is registered in tblEmployees. The reason is
because only the person who appears in a particular
record will be able to edit the record in the form.
I've added a DLookup to tblEmployees, but keep getting
Run-Time Error 2001 which says "You canceled the previous
operation." I click on Help, but get a blank screen and
can't find an explanation of what's wrong. I have tried
putting the DLookUp in various forms, always with the
same results. A watch on fOSUserName appears in the forms.
Here is the code:
-----------------------------
Option Compare Database
Private Declare Function apiGetUserName
Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim mFirstName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
mFirstName = DLookup
("[FirstName]", "tblEmployees", "[UserNTID] =
fOSUserName")
Else
fOSUserName = vbNullString
End If
End Function
the user's network name. (I got the code from a MS
support site.) It works fine, but I need to verify that
the user is registered in tblEmployees. The reason is
because only the person who appears in a particular
record will be able to edit the record in the form.
I've added a DLookup to tblEmployees, but keep getting
Run-Time Error 2001 which says "You canceled the previous
operation." I click on Help, but get a blank screen and
can't find an explanation of what's wrong. I have tried
putting the DLookUp in various forms, always with the
same results. A watch on fOSUserName appears in the forms.
Here is the code:
-----------------------------
Option Compare Database
Private Declare Function apiGetUserName
Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim mFirstName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
mFirstName = DLookup
("[FirstName]", "tblEmployees", "[UserNTID] =
fOSUserName")
Else
fOSUserName = vbNullString
End If
End Function