Solved

using ENVIRON$("USERNAME")

Posted on 2004-08-02
9
1,554 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:mdbdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 300 total points
ID: 11694355
Hi Tim

Environ always looks at your environment

so a better option might be to use the API call

place this code in a module

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

public function GetMyUsername() as String
    Dim s As String
    Dim lrv As Long
   
    s = String(1024, 0)
   
    lrv = GetUserName(s, 1024)
    If lrv <> 0 Then GetMyUsername = Mid(s, 1, InStr(s, Chr(0)) - 1) Else GetMyUsername = ""
End Sub
0
 
LVL 32

Expert Comment

by:jadedata
ID: 11694365
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...
0
 
LVL 2

Author Comment

by:mdbdev
ID: 11694603
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Assisted Solution

by:jadedata
jadedata earned 200 total points
ID: 11694647
A function call is a function call, no matter where its being called from.  

"Undefined function" means that a process can not "see" the function in its vast library of code in order to run the function.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 11694735
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()
0
 
LVL 2

Author Comment

by:mdbdev
ID: 11695511
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
0
 
LVL 32

Expert Comment

by:jadedata
ID: 11695816
How about using the MSAccess runtime engine to compensate?  You can do this if you have MSOffice Developer
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 11695986
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
0
 
LVL 2

Author Comment

by:mdbdev
ID: 11702138
thanks you gentlemen, Rock your code worked great (once I got the DNS issues resolved)

thanks again
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question