|
-
July 6th, 2007, 10:55 PM
#1
Access2003 - Trying to reference My.User Object
I am trying to access the My.User object in the standard VB Library. I am trying to log the username of the person updating my access 2003 database form.
It looks like the default library that is loaded by Access 2003 does not contain all the stardard VB objects.
When I try to change the library, i would get an error because some of my form already reference certain VB object. I am trying to avoid re-creating my DB.
Is there a different way to obtain the windows login info? or is there a way to import the right library so i can reference the object?
-
July 6th, 2007, 11:22 PM
#2
Re: Access2003 - Trying to reference My.User Object
Try this, as long as you posted in the VB6 forum. Otherwise, you can modify it for VBA.
Code:
Option Explicit
Private Enum EXTENDED_NAME_FORMAT
NameUnknown = 0
NameFullyQualifiedDN = 1
NameSamCompatible = 2
NameDisplay = 3
NameUniqueId = 6
NameCanonical = 7
NameUserPrincipal = 8
NameCanonicalEx = 9
NameServicePrincipal = 10
End Enum
Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpNameBuffer As String, ByRef nSize As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim sBuffer As String, Ret As Long
sBuffer = String(256, 0)
Ret = Len(sBuffer)
If GetUserNameEx(NameSamCompatible, sBuffer, Ret) <> 0 Then
MsgBox "Username: " + Left$(sBuffer, Ret)
Else
MsgBox "Error while retrieving the username"
End If
End Sub
or this one, that I saw posted around here: 
Code:
Option Explicit
' Originally posted by ROBDOG888
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function CurrentUser() As String
Dim strBuff As String * 255
Dim x As Long
CurrentUser = ""
x = GetUserName(strBuff, Len(strBuff) - 1)
If x > 0 Then
x = InStr(strBuff, vbNullChar)
If x > 0 Then
CurrentUser = UCase(Left$(strBuff, x - 1))
End If
End If
End Function
Private Sub Form_Load()
MsgBox CurrentUser
End Sub
-
July 7th, 2007, 12:53 AM
#3
Re: Access2003 - Trying to reference My.User Object
@rlsport: You are confusing/mixing VB.NET 2005 with Access VBA code.
In Access VBA there is no "My.User" class. That is found in VB.NET 2005.
Are your users logging into Access with workgroup security, database password, or simply by double clicking on the mdb file in Explorer and opening it?
This sounds like its entirely inside Access VBA but using either one of th code examples dave posted ( ) will work but for the Windows logon user name and not an Access user logon name.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|