View Full Version : Error on open trying to grab username


Amy35
04-02-2002, 10:16 AM
I used the code I found on this website (from Pat Hartman)to grab the current user name. When I put it in, I get the following error: The exp on open you entered as the event property setting produced the following error: "Only comments can appear after End Sub, End Function or End Property." It does look as though I am getting the user name, but the error stops you in your tracks.

Here's the code:

Option Compare Database
Option Explicit

Declare Function wu_WNetGetUser Lib "advapi32.dll" Alias "GetUserNameA" (ByVal sUser As String, nBuffer As Long) As Long
Function NetwareCurUser() As String

End Function
Dim sUser As String
Dim nBu As Long
Dim x As Variant

nBu = 8
sUser = Space(nBu)
x = wu_WNetGetUser(sUser, nBu)
sUser = Left(sUser, nBu - 1)

If IsNull(sUser) Then
MsgBox "Incorrect logon"
Else
NetwareCurUser = sUser
End If
End Function


Am I putting the code in the wrong place?
Thanks!

Amy

Amy35
04-02-2002, 10:39 AM
Thanks! I took the End Function out and am still getting the same error message. Any other ideas? Thanks!

Amy

Pat Hartman
04-02-2002, 10:59 AM
I cut and pasted the code and after removing the extraneous End Function, it worked correctly.

Amy35
04-03-2002, 04:46 AM
Pat-
Thanks for your help...Early this morning (perhaps a little too early) I had typed up a reponse that included yet another error message. I commented out the code that was causing the error (thereby creating more work later on) and it works great. Thanks so much!

Amy

[This message has been edited by Amy35 (edited 04-03-2002).]