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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>> >
>> >
>