'WNetGetUser' needs which Library? (1 Viewer)

noboffinme

Registered User.
Local time
Tomorrow, 03:16
Joined
Nov 28, 2007
Messages
288
Hi

I'm getting a 'Sub or Function not defined' error when the MS Access 2007 code comes across 'WNetGetUser'.

I'm trying to out why this happens as I believe it's because the Reference Library isn't available to it.

I can't work out though which library is required, any suggests??
 

noboffinme

Registered User.
Local time
Tomorrow, 03:16
Joined
Nov 28, 2007
Messages
288
Thanks JANR but I've already seen this & it doesn't provide the Reference Library required for WNetGetUser, only Mprdll which isn't what I need.

I have another db where the below code works OK & I have made sure all the same libraries are selected except for one which is a part of SP4.

I'm adding the libraries by going to Tools >>> References in the IDE.

Here's the code that works & is exactly the same;

One other diff is the one that works was created in Access 2003 & this new one is 2007.

---------------------------------------------------------------------Private Sub Comment_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim myuser As String

' Buffer size for the return string.
Const lpnLength As Integer = 255

' Get return buffer space.
Dim Status As Integer

' For getting user information.
Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product.
Status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred.
'If status = NoError Then

' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
' Else
' An error occurred.
' MsgBox "Unable to get the name."
' End
' End If

myuser = lpUserName

Me.Update_Memo = myuser

'Display the name of the person logged on to the machine.
'MsgBox "The person logged on this machine is: " & lpUserName

SendKeys "^{END}"

If IsNull(Me.Update_Memo.Value) Then
Me.Update_Memo.Value = Me.Update_Memo.Value & " @ " & Now() & " : Update Note "
Else: Me.Update_Memo.Value = Me.Update_Memo.Value & " @ " & Now() & " : Update Note "
End If

If Not IsNull(Me.Update_Memo.Value) Then
If Len(Me.Update_Memo.Value) < 32767 Then
Me.Update_Memo.SelStart = Len(Me.Update_Memo.Value)
Else
SendKeys "^{END}"
End If
End If

End Sub

----------------------------------------------------------------------

The info I've found to resolve this type of error is to make the sub Public (doesn't help) or find the correct library.

I've attached the libraries that are set on the 2003 db where this code is working OK. Cheers
 

Attachments

  • refs.gif
    refs.gif
    10.2 KB · Views: 275

Users who are viewing this thread

Top Bottom