I am stuck with two log tables. First one is called tblLog which logs the user name that is entered into the frmLogin, with form opened, date and time. The second one is an AuditLog which logs the users pc name along with the form, and field that was updated. The second one is the preferred one but I would really need to add a date and time field to it as well as capturing the username from the frmLogin. I am trying to add this auditlog because we use a master practice list in excel and it is updated daily. However there have been times when something was accidently deleted. So the auditlog would help. If anyone can guide me in the right direction to get the final three items into the auditlog, I would be so happy, as it has given me a massive headache. It is a module:
Function WriteChanges()
Dim f As Form
Dim c As Control
Dim frm As String
Dim user As String
Dim sql As String
Dim changes As String
Dim db As DAO.Database
Set f = Screen.ActiveForm
Set db = CurrentDb
frm = Screen.ActiveForm.Name
user = Application.CurrentUser
changes = ""
sql = "INSERT INTO AuditTrail " & _
"([Form Name], [User], [Changes Made]) " & _
"VALUES ('" & frm & "', '" & empName & "', "
For Each c In f.Controls
Select Case c.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
If IsNull(c.OldValue) And Not IsNull(c.Value) Then
changes = changes & _
c.Name & "--" & "BLANK" & "--" & c.Value & _
vbCrLf
ElseIf IsNull(c.Value) And Not IsNull(c.OldValue) Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & "BLANK" & _
vbCrLf
ElseIf c.Value <> c.OldValue Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & c.Value & _
vbCrLf
End If
End Select
Next c
sql = sql & "'" & changes & "');"
db.Execute sql, dbFailOnError
Set f = Nothing
Set db = Nothing
End Function
Function WriteChanges()
Dim f As Form
Dim c As Control
Dim frm As String
Dim user As String
Dim sql As String
Dim changes As String
Dim db As DAO.Database
Set f = Screen.ActiveForm
Set db = CurrentDb
frm = Screen.ActiveForm.Name
user = Application.CurrentUser
changes = ""
sql = "INSERT INTO AuditTrail " & _
"([Form Name], [User], [Changes Made]) " & _
"VALUES ('" & frm & "', '" & empName & "', "
For Each c In f.Controls
Select Case c.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
If IsNull(c.OldValue) And Not IsNull(c.Value) Then
changes = changes & _
c.Name & "--" & "BLANK" & "--" & c.Value & _
vbCrLf
ElseIf IsNull(c.Value) And Not IsNull(c.OldValue) Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & "BLANK" & _
vbCrLf
ElseIf c.Value <> c.OldValue Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & c.Value & _
vbCrLf
End If
End Select
Next c
sql = sql & "'" & changes & "');"
db.Execute sql, dbFailOnError
Set f = Nothing
Set db = Nothing
End Function
Last edited: