If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
User Logon Name
Hi all, I have tried to use this (as recommended in other posts, I have
deleted the comments only for this posting). 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 strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If ( lngX 0 ) Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = vbNullString End If End Function But i get an Error - Compile Error- Only comments may appear after end sub, end Function, end property. The compilation stops after the declare function. I know that its simple and I am missing it - please help. Thanks |
#2
|
|||
|
|||
The Declare statement has to go at the top of the module. You can put it
either before or after the Option Compare and Option Explicit statements, but it must come before any sub or function declaration. For example this is OK ... Option Compare Database Option Explicit Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Sub TestSub '... End Sub .... but this is *not* OK ... Option Compare Database Option Explicit Sub TestSub '... End Sub Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long -- Brendan Reynolds (MVP) "wannabeebetter" wrote in message ... Hi all, I have tried to use this (as recommended in other posts, I have deleted the comments only for this posting). 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 strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If ( lngX 0 ) Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = vbNullString End If End Function But i get an Error - Compile Error- Only comments may appear after end sub, end Function, end property. The compilation stops after the declare function. I know that its simple and I am missing it - please help. Thanks |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can I copy the contents of User Field 1 to User Field 4? | Robert Judge | Contacts | 1 | January 13th, 2005 02:39 PM |
Wrong user reported as having a file already open | CPCA-IT | General Discussions | 1 | December 1st, 2004 08:33 PM |
!!! OE deleted all message files after logon as different user, setting message stores to current folder | John Hupp | Outlook Express | 1 | September 3rd, 2004 07:11 PM |
New User needs to Import old Outlook Express emails and addresses | DougFromSydney | Contacts | 1 | June 17th, 2004 05:32 PM |
Two versions again-language issue | Otto | Setup, Installing & Configuration | 3 | May 28th, 2004 04:57 AM |