I've got a textbox that when in form view it displays the users name just fine. but when i go to set the control source to the LoginName so it saves it to the table I get this error:
Run-time error '-2147352567 (80020009)' You can't assign a value to this object.
I click on Debug and it brings up the code at the very bottom and highlights this:
Me.LoginName = GetCurrentUserN ame()
This is the code that I have in the module:
And in my form this is the complimenting code:
and I have a Macro that has the action to OpenForm and then my form name below.
Run-time error '-2147352567 (80020009)' You can't assign a value to this object.
I click on Debug and it brings up the code at the very bottom and highlights this:
Me.LoginName = GetCurrentUserN ame()
This is the code that I have in the module:
Code:
Option Compare Database Option Explicit Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function GetComputerName() As String On Error GoTo Err_GetComputerName Dim Username As String * 255 Call GetComputerNameA(Username, 255) GetComputerName = Left$(Username, InStr(Username, Chr$(0)) - 1) Exit_GetComputerName: Exit Function Err_GetComputerName: MsgBox Err.Description Resume Exit_GetComputerName End Function Public Function GetCurrentUserName() As String On Error GoTo Err_GetCurrentUserName Dim lpBuff As String * 25 Dim ret As Long, Username As String ret = GetUserName(lpBuff, 25) Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) GetCurrentUserName = Username & "" Exit_GetCurrentUserName: Exit Function Err_GetCurrentUserName: MsgBox Err.Description Resume Exit_GetCurrentUserName End Function
Code:
Private Sub Form_Open(Cancel As Integer) Me.LoginName = GetCurrentUserName() End Sub
Comment