There are several issues here.
I'm actually very surprised that what you've posted works in Access 97, as
you really should have the call to the Environ variable outside of the
quotes (although the value should be enclosed in quotes since it's a
string):
DLookUp("[organization]","tbl_AuthorizedUsers","[userid]= " & Chr$(34) &
Environ$("username") & Chr$(34))
or
DLookUp("[organization]","tbl_AuthorizedUsers","[userid]= '" &
Environ$("username") & "'")
In actual fact, though, the Environ function is a poor way to get username,
as environment variables are trivial to reset. You're far better off using
the API call shown in
http://www.mvps.org/access/api/api0008.htm at "The
Access Web"
When you say it works on some PCs but not on yours, what do you mean? Do you
get an error? If so, what's the error? If you type ?Environ$("username") in
the Immediate window (Ctrl-G) and hit Enter, do you get a value back? If
you're getting an error over the use of Environ, your references could be
messed up.
This can be caused by differences in either the location or file version of
certain files between the machine where the application was developed, and
where it's being run (or the file missing completely from the target
machine). Such differences are common when new software is installed.
On the machine(s) where it's not working, open any code module (or open the
Debug Window, using Ctrl-G, provided you haven't selected the "keep debug
window on top" option). Select Tools | References from the menu bar. Examine
all of the selected references.
If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.
If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
John Bigness said:
I have a query that works in Access 97 but does not work in Access 2000. The
query has the following expression that causes an error:
Expr1

LookUp("[organization]","tbl_AuthorizedUsers","[userid]=Environ$('use
rname')")
The query will retrieve the Organization from tbl_AuthorizedUsers using the
network logon of the current user.
In some PC's the query seems to work in Access 2000 but in mine it does not.
Any suggestions?