Undefined function 'ENVIRON' in expression

Discussion in 'Microsoft Access' started by l, Jan 12, 2007.

  1. l

    l Guest

    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
     
    l, Jan 12, 2007
    #1
    1. Advertisements

  2. l

    Guest 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

    "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
    >
    >
     
    Guest, Jan 12, 2007
    #2
    1. Advertisements

  3. l

    Dirk Goldgar Guest

    "l" <> wrote in message
    news:
    > 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
    www.datagnostics.com

    (please reply to the newsgroup)
     
    Dirk Goldgar, Jan 12, 2007
    #3
  4. missinglinq via AccessMonster.com, Jan 12, 2007
    #4
  5. "missinglinq via AccessMonster.com" <u28780@uwe> wrote in message
    news:6c319741fc4c8@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
    http://I.Am/DougSteele
    (no private e-mails, please)
     
    Douglas J. Steele, Jan 13, 2007
    #5
  6. l

    ll Guest

    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:
    > 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
    > >
    > >
     
    ll, Jan 22, 2007
    #6
  7. l

    ll Guest

    ll wrote:
    > 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:
    > > 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
    > > >
    > > >
     
    ll, Jan 22, 2007
    #7
  8. 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
    http://I.Am/DougSteele
    (no private e-mails, please)


    "ll" <> wrote in message
    news:...
    > 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:
    >> 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
    >> >
    >> >

    >
     
    Douglas J. Steele, Jan 22, 2007
    #8
  9. l

    ll Guest

    Doug,
    Thanks so much - that did the trick!

    Louis


    Douglas J. Steele wrote:
    > 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
    > http://I.Am/DougSteele
    > (no private e-mails, please)
    >
    >
    > "ll" <> wrote in message
    > news:...
    > > 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:
    > >> 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
    > >> >
    > >> >

    > >
     
    ll, Jan 22, 2007
    #9
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy

    Undefined function 'Left' in expression

    Andy, Jul 11, 2003, in forum: Microsoft Access
    Replies:
    1
    Views:
    412
    Dirk Goldgar
    Jul 11, 2003
  2. Andy

    Undefined function Left in expression

    Andy, Jul 14, 2003, in forum: Microsoft Access
    Replies:
    2
    Views:
    278
    Arvin Meyer
    Jul 14, 2003
  3. Kate McDonald

    Undefined function IsNull in expression

    Kate McDonald, Oct 2, 2003, in forum: Microsoft Access
    Replies:
    4
    Views:
    2,395
    Douglas J. Steele
    Oct 3, 2003
  4. SimonB

    Undefined function 'Date' in expression.

    SimonB, Dec 1, 2003, in forum: Microsoft Access
    Replies:
    1
    Views:
    459
    Bogdan Zamfir
    Dec 1, 2003
  5. Topmark
    Replies:
    2
    Views:
    382
    Topmark
    Oct 8, 2008
Loading...

Share This Page