Undefined function 'ENVIRON' in expression

L

l

Hi,
I have developed an Access application on my pc, where it works fine,
and then have tried it on another user's, but I get the following error
message: "Undefined function 'ENVIRON' in expression." I use this
statement in my SQL, and it has worked ok until now:
(Employees.userID)=(Environ("USERNAME"))

Would this have something to do with the library set up on the other
pc?

Thanks for any help you can provide,
Louis
 
G

Guest

Louis:

At first glance one would suspect a References problem, but putting that
aside, the use of the Environ function is not recommended. If you search on
'environ' here you'll find plenty of threads on this with alternative API
call suggestions. Here's my own however:

''''module starts''''
Option Compare Database
Option Explicit

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
lpBuffer As String, nSize As Long) As Long


Public Function GetUser() As String

Dim strBuffer As String
Dim lngSize As Long, lngRetVal As Long

lngSize = 199
strBuffer = String$(200, 0)

lngRetVal = GetUserName(strBuffer, lngSize)

GetUser = Left$(strBuffer, lngSize - 1)

End Function
''''module ends''''

which you could call in the query with:

Employees.UserID = GetUser()

Or you might like to consider calling the GetUser function at start-up to
update a column in a single row/single column local table, then join that
table to the Employees table in the query.

Ken Sheridan
Stafford, England
 
D

Dirk Goldgar

l said:
Hi,
I have developed an Access application on my pc, where it works fine,
and then have tried it on another user's, but I get the following
error message: "Undefined function 'ENVIRON' in expression." I use
this statement in my SQL, and it has worked ok until now:
(Employees.userID)=(Environ("USERNAME"))

Would this have something to do with the library set up on the other
pc?

Thanks for any help you can provide,
Louis

My guess is that it's the operation of Jet sandbox mode, which may be
set differently on different PCs:

http://support.microsoft.com/kb/294698/en-us
 
M

missinglinq via AccessMonster.com

Also, Environ is only available in versions later than AC2000.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
D

Douglas J. Steele

missinglinq via AccessMonster.com said:
Also, Environ is only available in versions later than AC2000.

Not so. It was in as long ago as Access 2.0 (I just looked it up in my
Access 2.0 documentation), and I suspect it may have been there from the
beginning.
 
L

ll

Ken,

I am trying to try this suggestion. I have put the code in its own
module, named GetUser, and then I've put the call in the query
(Employees.UserID = GetUser() ), but when I run the query I get
"Undefined function 'GetUser' in query".

Here is the SQL from the query:

SELECT DISTINCTROW Employees.EmployeeID, Employees.LastName,
Employees.FirstName
FROM Employees
WHERE ((Employees.EmployeeID)=GetUser())
ORDER BY Employees.LastName;


Any ideas are greatly appreciated. Thanks.

========================

Thanks,
Louis
 
L

ll

ll said:
Ken,

I am trying to try this suggestion. I have put the code in its own
module, named GetUser, and then I've put the call in the query
(Employees.UserID = GetUser() ), but when I run the query I get
"Undefined function 'GetUser' in query".

Here is the SQL from the query:

SELECT DISTINCTROW Employees.EmployeeID, Employees.LastName,
Employees.FirstName
FROM Employees
WHERE ((Employees.EmployeeID)=GetUser())
ORDER BY Employees.LastName;


Any ideas are greatly appreciated. Thanks.

========================

Thanks,
Louis
 
D

Douglas J. Steele

You can't name the module the same as any of the routines within it.

Rename the module to, say, mdlGetUser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top