J
jeanhurtado
I want to get the username and computer name when the user open a form
then want to add the username, computer name and, the record that the
user modified (primary number) to a table that is called users. This
table has 3 fields:
USERNAME, MOFIED RECORD AND COMPUTER NAME
I have the code to get the Computer Name and User Name but don't know
how to get that data(ComputerName, Username and Current Record) and
enter to the Users table. Need this to get a log of the users and what
record the user modified or enter a new record.
The Code to get Username
------------------------------------------------------------------------------
Private Sub form_Open(Cancel As Integer)
On Error GoTo ErrHandler
DoCmd.GoToRecord acDataForm, Me.Form, acNewRec
Me!UserName.Text = fOSUserName()
Me!ComputerName.Value = fOSMachineName()
Me!BeginTime.Value = Now()
RunCommand acCmdSaveRecord
Exit Sub
ErrHandler:
MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
End Sub
-----------------------------------------------------------------------------------------------------
The code to get Computer Name
------------------------------------------------------------------------------------------------------
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
Long
Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function
then want to add the username, computer name and, the record that the
user modified (primary number) to a table that is called users. This
table has 3 fields:
USERNAME, MOFIED RECORD AND COMPUTER NAME
I have the code to get the Computer Name and User Name but don't know
how to get that data(ComputerName, Username and Current Record) and
enter to the Users table. Need this to get a log of the users and what
record the user modified or enter a new record.
The Code to get Username
------------------------------------------------------------------------------
Private Sub form_Open(Cancel As Integer)
On Error GoTo ErrHandler
DoCmd.GoToRecord acDataForm, Me.Form, acNewRec
Me!UserName.Text = fOSUserName()
Me!ComputerName.Value = fOSMachineName()
Me!BeginTime.Value = Now()
RunCommand acCmdSaveRecord
Exit Sub
ErrHandler:
MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
End Sub
-----------------------------------------------------------------------------------------------------
The code to get Computer Name
------------------------------------------------------------------------------------------------------
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
Long
Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function