473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Create function that identifies current user's network login

I have an Access 2003 MDB database that uses the "currentuser()" function extensively (in queries and macros) to control what a particular user can see and do. In Access 2007 (which no longer uses user level security) the current user function now always returns "admin" , which pretty much breaks my database functionality. This database is used in a business environment and all PCs are connected to a common wired Novell network. I found instructions on the web on how to create a custom function that will return a current user's network login ID, which I think I can adapt to my database. However, I can not seem to get it to work.

I copied the below text in to a new module and named the module "fOSUserName". When I add a control to a form with the source as "=fOSUserName()", I get the following result: #Name?

I am new to VBA and modules so mistake may be something simple. I have read a lot of info on VBA and modules but have not learned enought to figure out my problem. Any advice?
Expand|Select|Wrap|Line Numbers
  1. ' This code was originally written by Dev Ashish.
  2. ' It is not to be altered or distributed,
  3. ' except as part of an application.
  4. ' You are free to use it in any application,
  5. ' provided the copyright notice is left unchanged.
  6. '
  7. ' Code Courtesy of
  8. ' Dev Ashish
  9. '
  10. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
  11.     "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  12.  
  13. Function fOSUserName() As String
  14. ' Returns the network login name
  15. Dim lngLen As Long, lngX As Long
  16. Dim strUserName As String
  17.     strUserName = String$(254, 0)
  18.     lngLen = 255
  19.     lngX = apiGetUserName(strUserName, lngLen)
  20.     If ( lngX > 0 ) Then
  21.         fOSUserName = Left$(strUserName, lngLen - 1)
  22.     Else
  23.         fOSUserName = vbNullString
  24.     End If
  25. End Function
Attached Images
File Type: jpg Current Network User Module.jpg (15.9 KB, 774 views)
Mar 15 '10 #1
3 7404
TheSmileyCoder
2,322 Expert Mod 2GB
Welcome to Bytes

Please remember to enclose your code in the code tags: [code][/code]
Try this:
Expand|Select|Wrap|Line Numbers
  1. Environ("UserName")
The Environ function will return varius envrironment variables, such as username. I also sometimes use it to get Environ("ComputerName"). It can be used for alot of other things as well.
Mar 15 '10 #2
ADezii
8,834 Expert 8TB
The Function Definition must be 'Public' or else it will be out of Scope and not accessible (See Line #1). The actual API Declaration, however, can remain Private as long as the Function itself resides in the same Module as the API Declaration.
Expand|Select|Wrap|Line Numbers
  1. Public Function fOSUserName() As String
  2. ' Returns the network login name
  3. Dim lngLen As Long
  4. Dim lngX As Long
  5. Dim strUserName As String
  6.  
  7. strUserName = String$(254, 0)
  8. lngLen = 255
  9.  
  10. lngX = apiGetUserName(strUserName, lngLen)
  11.  
  12. If (lngX > 0) Then
  13.   fOSUserName = Left$(strUserName, lngLen - 1)
  14. Else
  15.   fOSUserName = vbNullString
  16. End If
  17. End Function
Mar 17 '10 #3
NeoPa
32,556 Expert Mod 16PB
Function to Return UserName (NT Login) of Current User may help.
Mar 17 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Groupe Eurower | last post by:
Hi, I would like contribute to the PHP development but i don't really know where i can submit my codes ! In fact, i'm a Web Hosting and i authorize the utilisation of the mail() function. ...
4
by: Henro V | last post by:
I want the login name that somebody enters when starting the database to be set as a variable. I'll try to explain: I have a table (Engineer) that lists engineers (they are the users) The...
8
by: Omey Samaroo | last post by:
I have had most of my questions answered in this forum and learned a lot from reading others post. In fact, I have even discovered answers to questions that I thought were totally impossible and...
11
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read...
8
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
6
by: MuZZy | last post by:
Hi, I am looking to find a way to get currently logged in user's object GUID without querying ActiveDirectory. For example, when i log in to my laptop from home, I'm not on the office network so...
10
by: kai | last post by:
Hi, All I am trying to create a file folder for any login user, and create sub folders for the user on a web page. After the user login again, he can only sees his own folder on the Web page. I am...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
2
by: nja2222 | last post by:
I would like to create a page for my clients to login and check for updates on their accounts. Then I would like to create a page where my employees can login and make updates, specifically new file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.