Solved

Is Environ("Username") okay to use ?

Posted on 2011-03-21
3
319 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
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 19

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Error in Query 7 31
Error in query expression 3 36
Library not Registered 16 49
How autonumber field on a form 16 16
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now