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? - ' This code was originally written by Dev Ashish.
-
' It is not to be altered or distributed,
-
' except as part of an application.
-
' You are free to use it in any application,
-
' provided the copyright notice is left unchanged.
-
'
-
' Code Courtesy of
-
' Dev Ashish
-
'
-
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
-
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
-
-
Function fOSUserName() As String
-
' Returns the network login name
-
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
3 7453
Welcome to Bytes
Please remember to enclose your code in the code tags: [code][/code]
Try this:
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.
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. - Public Function fOSUserName() As String
-
' Returns the network login name
-
Dim lngLen As Long
-
Dim 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
NeoPa 32,579
Recognized Expert Moderator MVP Sign in to post your reply or Sign up for a free account.
Similar topics |
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)
|
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)
|
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.
|
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...
|
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
| |
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
|
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?
|
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
|
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
|
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'
...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |