B
Bob H
This is another Audit Trail I found, and would seem to better suit my
needs if it works.
The code breaks or is highlighted at this line below:
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
I created a table "tblAudit" and added the following fields:
FormName
ControlName
DateChanged
TimeChanged
PriorInfo
NewInfo
CurrentUser
Then copied and pasted the code below into a module behind the form I
want to rack the changes:
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the login name for Adminstrator use
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
Function TrackChanges()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strCtl As String
'Dim strReason As String
'strReason = InputBox("Reason For Changes") I remmed this out as I don't
yet want a box coming up asking me for a reason
strCtl = Screen.ActiveControl.Name
strSQL = "SELECT Audit.* FROM tblAudit;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset) <<< This line is
highlighted when have made a change to a record, then try to move to
anotherrecord
If rs.RecordCount > 0 Then rs.MoveLast
With rs
.AddNew
rs!FormName = Screen.ActiveForm
rs!ControlName = strCtl
rs!DateChanged = Date
rs!TimeChanged = Time()
rs!PriorInfo = Screen.ActiveControl.OldValue
rs!NewInfo = Screen.ActiveControl.Value
rs!CurrentUser = fOSUserName
'rs!Reason = strReason
.Update
End With
Set db = Nothing
Set rs = Nothing
End Function
Thanks
needs if it works.
The code breaks or is highlighted at this line below:
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
I created a table "tblAudit" and added the following fields:
FormName
ControlName
DateChanged
TimeChanged
PriorInfo
NewInfo
CurrentUser
Then copied and pasted the code below into a module behind the form I
want to rack the changes:
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the login name for Adminstrator use
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
Function TrackChanges()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strCtl As String
'Dim strReason As String
'strReason = InputBox("Reason For Changes") I remmed this out as I don't
yet want a box coming up asking me for a reason
strCtl = Screen.ActiveControl.Name
strSQL = "SELECT Audit.* FROM tblAudit;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset) <<< This line is
highlighted when have made a change to a record, then try to move to
anotherrecord
If rs.RecordCount > 0 Then rs.MoveLast
With rs
.AddNew
rs!FormName = Screen.ActiveForm
rs!ControlName = strCtl
rs!DateChanged = Date
rs!TimeChanged = Time()
rs!PriorInfo = Screen.ActiveControl.OldValue
rs!NewInfo = Screen.ActiveControl.Value
rs!CurrentUser = fOSUserName
'rs!Reason = strReason
.Update
End With
Set db = Nothing
Set rs = Nothing
End Function
Thanks