Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2007

Tip: Looking for answers? Try searching our database.

Public Functions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Todd K. - 24 Apr 2007 18:46 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.