A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

User Logon Name



 
 
Thread Tools Display Modes
  #1  
Old June 17th, 2005, 03:19 AM
wannabeebetter
external usenet poster
 
Posts: n/a
Default 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  
Old June 17th, 2005, 09:54 AM
Brendan Reynolds
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 12:05 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.