Bryan Carbonnell
carbonnb at gmail.com
Wed Sep 1 07:57:06 CDT 2004
On Wed, 1 Sep 2004 08:18:57 -0400, Nicholson, Karen <cyx5 at cdc.gov> wrote:
> It is great to be back on the list and working with Access again. It
> has been a while. I am looking for the user defined function to grab
> the network user name or id. I have inherited an Access 2002/SQL 2000
> back-end database run completely by macros with a pretty bad password
> scenario. This should keep me busy for a while.
The functions that Bobby and Stuart posted are fine for a windows
network, but if you are on a Novell network this will get you the
NovellID
'*+ Module API declarations
Private Declare Function NWCallsInit Lib "calwin32" _
(reserved1 As Byte, reserved2 As Byte) As Long
Private Declare Function NWDSCreateContextHandle Lib "netwin32" _
(newHandle As Long) As Long
Private Declare Function NWDSWhoAmI Lib "netwin32" _
(ByVal context As Long, ByVal objectName As String) As Long
Private Declare Function NWDSFreeContext Lib "netwin32" _
(ByVal context As Long) As Long
'*- Module API declarations
Function fGetNovellUserName() As String
'--------------------------------------------------------------------------
'.Purpose : To get Novell User Name
'.Author : Bryan Carbonnell
'.Date : 3-May-2002
'.Called by : frmUser Form_Open Event
'.Calls : NWCallsInit - API
'. NWDSCreateContextHandle - API
'. NWDSFreeContext - API
'.Revised : 3-May-2002 - Original
'--------------------------------------------------------------------------
On Error GoTo fGetNovellUserName_Error
Dim lngContextCode As Long
Dim lngContext As Long
Dim strMyName As String
' allocate space for user name
On Error GoTo fGetNovellUserName_Error
strMyName = Space(255)
' initialize NetWare client
lngContextCode = NWCallsInit(0, 0)
If lngContextCode <> 0 Then
'NW Client cannot be initialised, so we can't get the User Name
fGetNovellUserName = "NWCallsInit() - Cannot initialize"
Else
' a context is req'd for all NDS functions
lngContextCode = NWDSCreateContextHandle(lngContext)
If lngContextCode = 0 Then
'We have a valid Context, so we can do stuff
' now, get my name
lngContextCode = NWDSWhoAmI(lngContext, strMyName)
'Change to return username
If lngContextCode = 0 Then
strMyName = Left(strMyName, (InStr(strMyName, Chr(0)) - 1))
strMyName = Mid(strMyName, 4)
fGetNovellUserName = strMyName
End If
' clean-up
lngContextCode = NWDSFreeContext(lngContext)
End If
End If
Exit_fGetNovellUserName:
On Error GoTo 0
Exit Function
'Error Handler
fGetNovellUserName_Error:
'Display Error Message
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure " & .ProcedureName & " of " & .ModuleName
'Exit the procedure properly
Resume Exit_fGetNovellUserName
'For Debugging
Resume
End Function
--
Bryan Carbonnell - carbonnb at gmail.com
Life's journey is not to arrive at the grave safely in a well
preserved body, but rather to skid in sideways, totally worn out,
shouting "What a great ride!"