I'm calling code when a form is opened to return the user name and pass it to a field on the form. Everytime I go to open the form I get an error, "Object doesn't support this property or method (Error 438)". I've used this code before to write to a table without any problems. Any ideas?
Thanks
Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
Me.txtUser = username
End Sub
Code:
Option Compare Database
Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
Function username()
On Error GoTo Problem
Dim nSize As Long
Dim lpBuffer As String
Dim computername As String
Dim rec As Recordset
Dim inpname As String
nSize = 255
lpBuffer = Space$(nSize)
If GetUserName(lpBuffer, nSize) Then
username = Left$(lpBuffer, nSize)
Else
username = ""
End If
rec.Close
Exit Function
Problem:
Exit Function
MsgBox Err.Description
End Function
Thanks