Tags: access, application, database, developed, environ, expression, following, function, microsoft, mysql, oracle, sql, undefined, users
Undefined function 'ENVIRON' in expression
On Database » Microsoft Access
8,688 words with 8 Comments; publish: Wed, 04 Jun 2008 02:53:00 GMT; (25078.13, « »)
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
http://ms-access.itags.org/q_ms-access-database_192989.html
All Comments
Leave a comment...
- 8 Comments

- 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
"l" wrote:
> 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
>
#1; Wed, 04 Jun 2008 02:54:00 GMT

- "l" <barn104_1999.ms-access.itags.org.yahoo.com> wrote in message
news:1168616716.892791.97900.ms-access.itags.org.38g2000cwa.googlegrou ps.com
> 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
Dirk Goldgar, MS Access MVP
(please reply to the newsgroup)
#2; Wed, 04 Jun 2008 02:55:00 GMT

- 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 droptable.com
http://www.droptable.com/Uwe/Forums.aspx/access/200701/1
#3; Wed, 04 Jun 2008 02:56:00 GMT

- "missinglinq via droptable.com" <u28780.ms-access.itags.org.uwe> wrote in message
news:6c319741fc4c8.ms-access.itags.org.uwe...
> 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.
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
#4; Wed, 04 Jun 2008 02:57:00 GMT

- 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
Ken Sheridan wrote:[vbcol=seagreen]
> 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
> "l" wrote:
#5; Wed, 04 Jun 2008 02:58:00 GMT

- ll wrote:[vbcol=seagreen]
> 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
>
> Ken Sheridan wrote:
#6; Wed, 04 Jun 2008 02:59:00 GMT

- You can't name the module the same as any of the routines within it.
Rename the module to, say, mdlGetUser.
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
"ll" <barn104_1999.ms-access.itags.org.yahoo.com> wrote in message
news:1169479165.134699.90560.ms-access.itags.org.l53g2000cwa.googlegro ups.com...
> 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
>
> Ken Sheridan wrote:
>
#7; Wed, 04 Jun 2008 03:00:00 GMT

- Doug,
Thanks so much - that did the trick!
Louis
Douglas J. Steele wrote:[vbcol=seagreen]
> You can't name the module the same as any of the routines within it.
> Rename the module to, say, mdlGetUser.
> --
> Doug Steele, Microsoft Access MVP
> (no private e-mails, please)
>
> "ll" <barn104_1999.ms-access.itags.org.yahoo.com> wrote in message
> news:1169479165.134699.90560.ms-access.itags.org.l53g2000cwa.googlegro ups.com...
#8; Wed, 04 Jun 2008 03:01:00 GMT