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
 

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

Similar Threads

Update form field 2
Capitalise 6
Porting from 2003 to 2007 6
Update username 8
Retrieving and setting user logon name in a form 2
get network login name 14
Another audit Trail module 8
Function Parameters 1

Top