Link to home
Start Free TrialLog in
Avatar of mdbdev
mdbdevFlag for United States of America

asked on

using ENVIRON$("USERNAME")

Hello all,

I am using ENVIRON$("USERNAME") as criteria in a query. It works great locally on Windows 2000 & XP with Access 2K, XP, and 03. As soon as I put in on my server/domain it gives me an undefined error on either OS /version of access. The server is running 2K SP4 but does not have office installed on it. The SET command brings up the correct username on the workstations. Copying the front end to the local workstation does not work.

Any one have any suggestions / alternatives?

TY

Tim
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the context in which Environ$("UserName") is being used (post code)??

This is an Access function to retrieve the value of an OS variable...  It strikes me that without Access loaded on the machine that is running the code, there can be no successful function call...
Avatar of mdbdev

ASKER

Rock,

Thought about pulling it into a module. How can I use the value via the query (recordsource)?

Jade,

The calue is used in a query (recordsource) of a form as criteria where fieldname = Environ$("UserName"). The query is not a SQL string in VB rather just built in query builder.

I am loading office on the server now.

Tim
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
u should be able to use the function within the query
I tried it, for some reason the name GetMyUsername was playing ball, so I created a test function first, ensured it got called by a query then pasted my code in

my code

Public Function MyUName() As String
    Dim s As String
    Dim lrv As Long
   
    s = String(1024, 0)
   
    lrv = GetUserName(s, 1024)
    If lrv <> 0 Then MyUName = Mid(s, 1, InStr(s, Chr(0)) - 1) Else MyUName = ""
End Function


my query


SELECT MyUName()
Avatar of mdbdev

ASKER

Thanks guys,

I got the above code to work locally. Dont think installing office is an option as the client does not have office on his servers. Once I get my DNS issue resolved, I will test above code on domain.

TY AGAIN

Tim
How about using the MSAccess runtime engine to compensate?  You can do this if you have MSOffice Developer
Use the code that rocki posted to get the user name and then populate a text box on a hidden form

I do that with username, machine name and a few other key values.

Then you can reference the value of the text box that stores the user name in a query.

Mike
Avatar of mdbdev

ASKER

thanks you gentlemen, Rock your code worked great (once I got the DNS issues resolved)

thanks again