Solved

Is Environ("Username") okay to use ?

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

815 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

12 Experts available now in Live!

Get 1:1 Help Now