VBA function Environ()


  • In Access 2010 (VBA) I get an error: "Undefined function 'Environ' in expression"

    The code that fails is:

    Dim UserEntered as string
    UserEntered = Environ("Username")

    This has always worked in Access 2003 and according the help it should still work in 2010

    Any suggestions?


    Patrick Delisse

    Wednesday, November 07, 2012 3:21 PM


All replies

  • In the Visual Basic Editor, select Tools | References...

    See if there are references whose check box is ticked (they are listed at the top) that start with MISSING:

    Clear the check box of missing references, then select Debug | Compile <projectname> to see if the code is correct.

    Regards, Hans Vogelaar

    Wednesday, November 07, 2012 5:43 PM
  • I couldn't find a reference guide on MS's web sites, so here's my best guess:

    This won't work if you upgraded, but if you still have both versions running on some systems that you used:

    Go to the old system and look at Tools | References.

    Compare to the same list on the new system.

    If you upgraded, check the reference list for older versions. For example, Access 2003 is part of the Office 12 (internal version num) suite. If you something referring to Access or other package, but it's version 12, you probably need to add the one for version 14.

    Wednesday, November 07, 2012 9:26 PM
  • The References are set correctly. I found that the problem doesn't occur in the code section, but in one of the queries.

    I have a query that uses Environ("username") as a criteria.

    SELECT tbl_Gebruikers.Username, tbl_Gebruikers.logonname, tbl_Gebruikers.Personeelsnummer, tbl_Gebruikers.Afdeling
    FROM tbl_Gebruikers
    WHERE (((tbl_Gebruikers.logonname)=Environ("username")));

    This works fine on Access2003

    Patrick Delisse

    Thursday, November 08, 2012 6:36 AM
  • The Environ function can be used in VBA code, but it causes an error in expressions (i.e. in queries and in the control source of controls on a form or report) by default.

    See Functions and properties in Access 2007 blocked by sandbox mode. This article provides a list of blocked functions and describes how to disable the block.

    Regards, Hans Vogelaar

    • Marked as answer by PDE Thursday, November 08, 2012 7:17 AM
    Thursday, November 08, 2012 7:13 AM