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.
Robert Morley - 24 Apr 2007 20:53 GMT
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
>I use the following code to get the current user for automation purposes in
> my main form:
[quoted text clipped - 24 lines]
> 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.
Todd K. - 24 Apr 2007 21:08 GMT
Easy enough, thanks.
> 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).
[quoted text clipped - 29 lines]
> > 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.
Aaron Kempf - 05 May 2007 00:54 GMT
why are you resurrecting a decade-old database format and data access
library?
> 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).
[quoted text clipped - 29 lines]
> > 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.
Todd K. - 07 May 2007 15:32 GMT
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.
> why are you resurrecting a decade-old database format and data access
> library?
[quoted text clipped - 36 lines]
> > > 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.
Robert Morley - 07 May 2007 22:42 GMT
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
>I was just trying to find a solution to an issue I was facing. If you have
>a
[quoted text clipped - 43 lines]
>> > > of
>> > > pasting all of this code in each form I need to use the function in.
Todd K. - 08 May 2007 13:20 GMT
Will do, thanks.
> 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
[quoted text clipped - 49 lines]
> >> > > of
> >> > > pasting all of this code in each form I need to use the function in.
Aaron Kempf - 04 May 2007 01:11 GMT
Access has this built in
Select SUSER_SNAME()
> I use the following code to get the current user for automation purposes in
> my main form:
[quoted text clipped - 23 lines]
> 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.