Public Functions

T

Todd K.

I use the following code to get the current user for automation purposes in
my main form:

Option Compare Database

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String

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

Unfortunately I am not very experienced with modules/public functions, and I
was wondering how I could make this code public so that I could just
reference fOSUserName() in any of my forms in this database instead of
pasting all of this code in each form I need to use the function in.
 
R

Robert Morley

All you need to do is put it into a Module and add the word Public in front
of your Function declaration (i.e. Public Function fOSUserName() As String).


Rob
 
T

Todd K.

Easy enough, thanks.

Robert Morley said:
All you need to do is put it into a Module and add the word Public in front
of your Function declaration (i.e. Public Function fOSUserName() As String).


Rob
 
A

Aaron Kempf

why are you resurrecting a decade-old database format and data access
library?
 
T

Todd K.

I was just trying to find a solution to an issue I was facing. If you have a
better solution, I would be glad to hear it.
 
R

Robert Morley

Aaron's a known troll in the various Access newsgroups who is rarely, if
ever, helpful and frequently posts lies and misinformation. Just ignore him
(or outright block him, like I have).


Rob
 
T

Todd K.

Will do, thanks.

Robert Morley said:
Aaron's a known troll in the various Access newsgroups who is rarely, if
ever, helpful and frequently posts lies and misinformation. Just ignore him
(or outright block him, like I have).


Rob
 
Top