P
PJFry
I want to create an audit log for a process database at my office.
Basically, everytime a change is made to certain parts of the form I want to
log the change and who did it. For example, when someone checks a box that
indicates an issue as been resolved, the persons network ID, the change made
and date and time the change was made will be recorded. Here is what I have
so far:
***********************************************************
Private Sub Resolution_Click()
Me.dtmDateResolved = Date
Me.dtmTimeResolved = Time
Dim strSQL As String
Dim UserID As String
UserID = fOSUserName()
strSQL = "INSERT INTO tChangeLog(txtUserID) VALUES ( " & UserID & ");"
DoCmd.RunSQL strSQL
End Sub
***********************************************************
where UserID = fOSUserName() is
**********************************************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
************************************************************
As you can see, I want to use an INSERT INTO statement to write a variable
to the table. I can do it if I define the value in the statement:
strSQL = "INSERT INTO tChangeLog(txtUserID) VALUES ('pjfry');"
but I don't know how to use variables in the statement.
Thoughts?
Thanks in advance
PJ
Basically, everytime a change is made to certain parts of the form I want to
log the change and who did it. For example, when someone checks a box that
indicates an issue as been resolved, the persons network ID, the change made
and date and time the change was made will be recorded. Here is what I have
so far:
***********************************************************
Private Sub Resolution_Click()
Me.dtmDateResolved = Date
Me.dtmTimeResolved = Time
Dim strSQL As String
Dim UserID As String
UserID = fOSUserName()
strSQL = "INSERT INTO tChangeLog(txtUserID) VALUES ( " & UserID & ");"
DoCmd.RunSQL strSQL
End Sub
***********************************************************
where UserID = fOSUserName() is
**********************************************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
************************************************************
As you can see, I want to use an INSERT INTO statement to write a variable
to the table. I can do it if I define the value in the statement:
strSQL = "INSERT INTO tChangeLog(txtUserID) VALUES ('pjfry');"
but I don't know how to use variables in the statement.
Thoughts?
Thanks in advance
PJ