Function Parameters

M

Mike

This is probably very simple.
I copied the code from
http://www.mvps.org/access/api/api0008.htm
and pasted it into a module called modGetRacfID (here is the code)
Option Compare Database

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
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

MsgBox ("User id is " & fOSUserName & "")
End Function
'******************** Code End **************************


Then from the Form_frmPWT I need to call this function and then return the
fOSUerName to Form_frmPWT.

I can get the function to work but being a newbie, do not know how to return
the variable
 
F

fredg

This is probably very simple.
I copied the code from
http://www.mvps.org/access/api/api0008.htm
and pasted it into a module called modGetRacfID (here is the code)
Option Compare Database

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
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

MsgBox ("User id is " & fOSUserName & "")
End Function
'******************** Code End **************************

Then from the Form_frmPWT I need to call this function and then return the
fOSUerName to Form_frmPWT.

I can get the function to work but being a newbie, do not know how to return
the variable

Using an unbound control on your form, set it's control source to:
="User id is " & fOSUserName()

You also can comment out the
MsgBox ("User id is " & fOSUserName & "")
in the function (by placing an apostrophe (') in front of the word
MsgBox) as it is no longer needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top