Question : MS Access 10.0 Object Library Reference

I have a database that is widely used in my organization.  My LAN team has rolled out Access 2003 to some users.  These users have 11.0 object Library on thier PCs.  

My database is failing because I am using Environ("username") in my application.  Does anyone know how to resolve this, or maybe know of an easy alternative to capturing the username?  I use the username in queries, forms, and reports.  

Thank you,
Scotto13

Answer : MS Access 10.0 Object Library Reference

You can use this API call instead...

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

Public Function fn_get_user_name() As String

'Returns the network ID of the person that logged into the machine that is running this Access application:
'This is not the same as the Access security user.

'Visual Basic Source Code Library, The Waite group, Chapter 12.5

On Error GoTo err_fn_get_user_name

Dim str_user_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_user_name = Space(80)
lng_buffer_size = Len(str_user_name)

lng_ret_code = GetUserName(str_user_name, lng_buffer_size)

lng_null_character_position = InStr(str_user_name, Chr(0))
If lng_null_character_position > 0 Then
    str_user_name = Left(str_user_name, lng_null_character_position - 1)
Else
    str_user_name = " "
End If

fn_get_user_name = UCase(str_user_name)

exit_fn_get_user_name:
    Exit Function
   
err_fn_get_user_name:
    fn_get_user_name = "Not able to get user name."
    Resume exit_fn_get_user_name
   
End Function
Random Solutions  
 
programming4us programming4us