Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defaulting User Login Name In Field

Status
Not open for further replies.

bigmerf

MIS
Oct 4, 2002
247
US
I created a database using Access 2003 and created a field called "UserName" where I read the user's login name to their PC and default this for new orders. I used the following to do this:

=Environ("username")

Now, when accessing this database using Access 2007 or later, I get #NAME in the box.

Is their another function that I should be using or another line of code to use as the default to pull the user name from the PC?

Any help would be GREAT!

Thanks!
 
Dunno if this help, but i found it doing a G! search..
The Environ() function works great unless you have the Sandbox mode turned on in
Access 2003. You will need to add this public function to your Access 2003 db's if you
want to continue using the Environ() funciton...

'This function is used to allow the use of the Environ function in Access 2003
Code:
Public Function Environ(Expression)
On Error GoTo Err_Environ

Environ = VBA.Environ(Expression)

Exit_Environ:
Exit Function

Err_Environ:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Environ

End Function

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Thanks for you reply. Basically I just had to add a couple lines of code to move the value of the PC user to the field:

Dim User as String

User = Environ("UserName")
me.FieldA = User

Thanks again!
 
personnaly I use windows API for user name and computer name.

'used for machine name
Declare Function WNetGetUserA Lib "mpr" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long



Function GetUserID() As String

Dim sUserNameBuff As String * 255

sUserNameBuff = Space(255)

Call WNetGetUserA(vbNullString, sUserNameBuff, 255&)
GetUserID = left$(sUserNameBuff, InStr(sUserNameBuff, vbNullChar) - 1)

End Function



Function GetWSID() As String

Dim sBuffer As String * 255
Dim x As Long

If GetComputerNameA(sBuffer, 255&) > 0 Then
GetWSID = left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
Else
GetWSID = "?"
End If

End Function



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top