Unknown Function 'Environ'

mcbass1

Registered User.
Local time
Today, 15:45
Joined
Sep 7, 2007
Messages
41
This error seems to be showing itself on a handful of pc's that use the database. The problem seems to be pc specific, not user specific, but I have been unable to find a fix. I had one of the users that is getting the error go into the vb script editor of the database in question and type in print environ("username") in the immediate window, and it returned her username. But, when the database loads without using the bypass key, it gives the error: Unknown Function 'Environ'.

Any info would be greatly appreciated.

Thank you,
Mike
 
Mike,

This may be caused by a MISSING Reference Library.
 
Try calling it like

VBA.Environ("username")

instead.
 
Mike,

This may be caused by a MISSING Reference Library.

Or another Access 2007 "feature". I created a wrapper function for environ that goes something like this:

Code:
Function MyEnviron(username As String) As String
  MyEnviron = VBA.Environ(username)
End Function

Now I just call MyEnviron and it works on all computers, even those stuck with Access 2007.

SHADOW
 
I love this forum!

Thanks Shadow, I used your suggestion and created a function that I call from the query - It worked perfectly. And thank you too Bob. You've helped me out of more jams than I want to remember.

Mike
 
I love this forum!

Thanks Shadow, I used your suggestion and created a function that I call from the query - It worked perfectly. And thank you too Bob. You've helped me out of more jams than I want to remember.

Mike

You're welcome.

The reason I use wrapper functions like that is just as you said - it's used as criteria in a query. You can't use function calls like VBA.environ in a query; it won't recognize it as a function.

My rule of thumb is to create these types of functions for most VBA functions that I think I will be using in an application such as Date() or Now() and so on. If people are missing the references, the program will crash which is not fun. This ensures me that it will work correctly on every computer.

SHADOW
 
:confused::confused::confused:
Hi Guys, I'm, also have the same issue.
I'm using =Environ("username") as a Default Vaule in one of mt tables.
It seems to work when you have the database open but then you open the html, i get an error saying 'Unknown finction Environ'

Is there away around this?
Thanks guys :)
 
:confused::confused::confused:
Hi Guys, I'm, also have the same issue.
I'm using =Environ("username") as a Default Vaule in one of mt tables.
It seems to work when you have the database open but then you open the html, i get an error saying 'Unknown finction Environ'

Is there away around this?
Thanks guys :)

Have you tried what Shadow9449 suggested for the other poster?
 
Thanks for the very quick reply Bob. I'm a real newbie to all of this and did try what Shadow suggested but knowing me, I couldn't get it to work.
I'm using Data Access Page when I pasted the function in, it just errored out.
My other funtions look like this:
</SCRIPT>
<SCRIPT language=javascript>
function offcheckradio ()
{
TIOFORM.Option12.disabled = true;
TIOFORM.Option13.disabled = true;

}
</SCRIPT>
 
Hello,

My office is in the process of upgrading to Access 2007... ugh!
Im also having the Environ problem and have tried the above fix, but how can I reference MyEnviron in a query and also in a form?
This is my query that needs the MyEnviron added.
SELECT UID_tblID.UserID, UID_tblID.ShortName FROM UID_tblID;
Previously the UserID field was simply Environ("USERNAME")
Thanks
 
Hello,

My office is in the process of upgrading to Access 2007... ugh!
Im also having the Environ problem and have tried the above fix, but how can I reference MyEnviron in a query and also in a form?
This is my query that needs the MyEnviron added.

Previously the UserID field was simply Environ("USERNAME")
Thanks

Instead of using environ("username"), use MyEnviron. The MyEnviron function will do the work for you. It's that simple.

SHADOW
 
Hi Shadow,

Thanks for the reply. Ive created the MyEnviron but I cant see how to add it into my query. If i put MyEnviron as criteria, it simply searches for that word.
How do I refer to the user name in MyEnviron in a query?

Thanks
 
This Works:

Code:
With CurrentDb.QueryDefs("qryEventLogParameter")
    .Parameters("p1") = (Environ$("Username"))  'User ID (Text)
        .Parameters("p2") = Request_ID   ' TblPrimaryID long Integer
       .Parameters("p3") = "tblrequest"   'Table Name
       .Parameters("p4") = 1     'Function Long Integer
        .Parameters("p5") = "Add New Request" 'Notes (Text)
           .Parameters("p6") = Me.Name 'returns curent form name

This is a description of a prameter query using the module discussed here.
 
but a function used in a criteria row needs to have brackets

so

myenviron()

is the correct syntax

---------
on reflection, ignore this - myenviron needs a parameter also
 
Are you using the function and then using MyEnviron("UserName") as the criteria? If that still fails, are you able to upload the database and indicate which query is causing the problem.

SHADOW
 

Users who are viewing this thread

Back
Top Bottom