Solved

Is Environ("Username") okay to use ?

Posted on 2011-03-21
3
318 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 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
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 19

Assisted Solution

by:darbid73
darbid73 earned 250 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now