Calling from a function.

martin461

New member
Local time
Today, 00:06
Joined
Jul 29, 2009
Messages
9
God I feel soo think :mad:...I am beating all round the bush to do this, I have forgotten how to do it thou...here go's:

I have this code in my module, called 'Module1', as below:


Code:
Option Compare Database
Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
Function ReturnUserName() As String
' returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
    tString = ""
    On Error Resume Next
    sLen = GetUserName(rString, 255)
    sLen = InStr(1, rString, Chr(0))
    If sLen > 0 Then
        tString = Left(rString, sLen - 1)
    Else
        tString = rString
    End If
    On Error GoTo 0
    ReturnUserName = UCase(Trim(tString))
End Function


Whether this code works or not I dont no the point is I cannot call from it lol, I want to write some code that will call from my main form when a command button is clicked:

for example...

Private Sub Command145_Click()

'set variable user name
'grab user name from function in module and assign to variable
'put variable in a text box

End Sub


Simple enough..! well not for me not me lol, I have done this sort of thing in java but not for a while, I'am sure you can do the whole lot in one line of code...lol

Please help asap :)
 
thankyou, knew it was simple...lol

Code:
Private Sub Command145_Click()
    Me.lblUserName1.Caption = ReturnUserName()
End Sub
 

Users who are viewing this thread

Back
Top Bottom