StarvinMarvin
still quite the noob
- Local time
- Today, 00:48
- Joined
- Mar 8, 2010
- Messages
- 171
Wanted to add the GetUserName code to a query for GetUserName and Now() to use to timestamp record entries.
Works in the query after I create the function, after I save the function in the module and restart I get the undefined function error....
Seems like this is ending up private or something... tried adding Public before the Function definition and still no go. Does it have to be in the declarations? Just adding Public up there doesn't work.
The version I'm using is:
This is obviously simple but I'm not seeing when this becomes private, if that's what's happening, and what's necessary to make it public.
side note...just tried the other version at mvps.org and I get the same thing, works until I save it, can't be found after opening.
Works in the query after I create the function, after I save the function in the module and restart I get the undefined function error....
Seems like this is ending up private or something... tried adding Public before the Function definition and still no go. Does it have to be in the declarations? Just adding Public up there doesn't work.
The version I'm using is:
Code:
[COLOR=blue]Declare Function[/COLOR] WNetGetUser Lib "mpr.dll" _
[COLOR=blue]Alias[/COLOR] "WNetGetUserA" (ByVal lpName [COLOR=blue]As String[/COLOR], _
[COLOR=blue]ByVal[/COLOR] lpUserName [COLOR=blue]As String[/COLOR], lpnLength As Long) [COLOR=blue]As Long[/COLOR]
[COLOR=blue]Const[/COLOR] NoError = 0 [COLOR=darkgreen]'The Function call was successful[/COLOR]
[COLOR=navy]Function[/COLOR] GetUserName() [COLOR=navy]As String[/COLOR]
[COLOR=navy]Dim[/COLOR] LUserName [COLOR=navy]As String[/COLOR]
[COLOR=navy]Const[/COLOR] lpnLength [COLOR=navy]As Integer[/COLOR] = 255
[COLOR=navy]Dim[/COLOR] status [COLOR=navy]As Integer[/COLOR]
Dim lpName
[COLOR=darkgreen]' Assign the buffer size constant to lpUserName.[/COLOR]
LUserName = Space$(lpnLength + 1)
[COLOR=darkgreen]' Get the log-on name of the person using product[/COLOR].
status = WNetGetUser(lpName, LUserName, lpnLength)
[COLOR=darkgreen]' See whether error occurred.[/COLOR]
[COLOR=navy]If[/COLOR] status = NoError Then
[COLOR=darkgreen]' This line removes the null character. Strings in C are null-[/COLOR]
[COLOR=darkgreen] ' terminated. Strings in Visual Basic are not null-terminated.[/COLOR]
[COLOR=darkgreen] ' The null character must be removed from the C strings to be used[/COLOR]
[COLOR=darkgreen] ' cleanly in Visual Basic.[/COLOR]
LUserName = Left$(LUserName, InStr(LUserName, Chr(0)) - 1)
[COLOR=navy]Else[/COLOR]
[COLOR=darkgreen]' An error occurred.[/COLOR]
[COLOR=navy]MsgBox[/COLOR] "Unable to get the name."
[COLOR=navy]End[/COLOR]
[COLOR=navy]End If[/COLOR]
GetUserName = LUserName
[COLOR=navy]End Function[/COLOR]
This is obviously simple but I'm not seeing when this becomes private, if that's what's happening, and what's necessary to make it public.
side note...just tried the other version at mvps.org and I get the same thing, works until I save it, can't be found after opening.
Last edited: