Solved

Is Environ("Username") okay to use ?

Posted on 2011-03-21
3
321 Views
Last Modified: 2012-05-11
This may seem an odd question.
I have recently started using Environ("Username") to determine the log in name of the database user.

It seems to work perfectly fine.  However, I used to use a more complicated piece of code that confused me somewhat. (Unfortunately, I do not have this code to hand).

Is there any reason NOT to use Environ("Username")??

Thanks!
0
Comment
Question by:Patrick O'Dea
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 35180323
i never have any problem using Environ("Username")

if you are ahving problem with that you can use the codes from

http://www.mvps.org/access/api/api0008.htm

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

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If ( lngX > 0 ) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

Open in new window

0
 
LVL 20

Assisted Solution

by:darbid73
darbid73 earned 250 total points
ID: 35180415
Answering your question specifically

<Is there any reason NOT to use Environ("Username")??>

A user can change the Environ variables themselves.  Out of 20 computers that I have used this variable on - about 5 people have changed this variable to nothing. Or it was never inserted no idea, but the string is empty.
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35180527
Thank you both for your comprehensive answers.

Since I understand the environ("Username") code I will stick with it for the moment.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

820 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