473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create function that identifies current user's network login

1 New Member
I have an Access 2003 MDB database that uses the "currentuse r()" 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 "fOSUserNam e". 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 7453
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
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("Comput erName"). It can be used for alot of other things as well.
Mar 15 '10 #2
ADezii
8,834 Recognized Expert Expert
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,579 Recognized Expert Moderator MVP
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
2387
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. Meanwhile, this function permit to send mail anonyme ! (the sender is the apache user in fact)
4
4531
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 relevant fields are Engineer.Name Engineer.Code (where the login in the database is the Engineer.Code)
8
1782
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 absurd to ask, and for that I will continue to be a fan to this NG. Today I have one question (two parts): How do I create a table to log users that the application has booted out ? Does it log the users by computer name ? Thanks very much.
11
3076
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 files on Windows domain network shared drives and also on shared via Samba Unix drives, which is equivalent to writing/reading to the workgroup computer. Please point, if possible, to detailed step by step description of what needs to be done. Thank...
8
4903
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 user's Name property in the WindowsPrincipal's IIdentity interface. Where can I find the role that the user is assigned for the current login? I only want the one role which is assigned for the current user, not all of
4
12444
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
6
5668
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 i can't reach AD but I'm sure i still can get my AD's objectGUID, as the profile is cached locally. Any ideas?
10
14306
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 planning to use VB2005 or C#. I look the help files and searched on the web, I cannot find the answer. Is this possble in ASP.NET 2.0? Thanks
4
6916
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 function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
2
2785
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 uploads, to the clients accounts. I have seen similar sites everywhere, such as bank websites, USPS site, et cetera. What is required to accomplish this? I'm trying to do this with the PHP, MySQL and Adobe CS3 Master collection's 'Dreamweaver CS3' ...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.