Re: Form Calculation writes record to Audit Log



On Fri, 21 Sep 2007 13:57:04 GMT, "ARC" <acolonna35@xxxxxxxxxxx>
wrote:

Just some observations:
LogType: Rather than passing in a string and converting it to a
number, create an Enum:
Enum enumLogTypes 'Keep in sync with tblLogTypes
LT_Quote = 1
LT_Invoice
LT_Payment
'etc.
End Enum
Then change this function to:
Public Function AuditLog(LogType As enumLogTypes, ...etc.
Benefits: faster because the entire Case statement can be omitted, and
you get nice intellisense while calling the function.

tblLogTypes (I wasn't sure if you have one) will later help with audit
reports.

You may want to cache that UseAuditLog flag in a global variable
rather than hit the db every time you call the AuditLog function.
Btw, your test "If Not rs.BOF " comes too late. You already did
"rs.MoveFirst" which only works if there is a record.

Formatting rs!LogDate is not useful, assuming this is a date field.
Just write:
rs!LogDate=Now()
or set this as the default in the table.

I think:
db.Close
is not useful on CurrentDB. See usenet for lengthy discussions about
..Close and set to Nothing.

-Tom.


What I did was to create an Audit log function where I only run the function
for certain things. For example, on an invoice, if the user changes the
invoice status, in the after_update code, I'll call:

Call AuditLog("InvoiceStatus", "Changed Status from Delivered to Ordered,
Invoice #: " & Forms!frmOpt.Form!InvoiceNo & ", Invoice Amount: " &
Format(Me!txtTotalCalc, "Currency") & ", Customer: " &
Forms!frmOpt.Form!cboCustomer.Column(5))


So basically I'm passing everying I want to write to the Audit Log proc,
which will then add in the machine name and time/date stamp. Here's the
Audit Log proc:

Public Function AuditLog(LogType As String, LogDesc As String) As Boolean
On Error GoTo ErrRtn
Dim db As Database, rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("tGlobal", DB_OPEN_SNAPSHOT)
rs.MoveFirst
If Not rs.BOF Then
If rs!UseAuditLog = 0 Then
rs.Close
db.Close
Exit Function
End If
End If
rs.Close
Set rs = db.OpenRecordset("tAudit", DB_OPEN_DYNASET)
rs.AddNew
rs!LogDate = Format(Now(), "General Date")
rs!LogUser = CurrentMachineName()
Select Case LogType
'1;"Deleted Quotes";2;"Deleted Invoices";3;"Deleted Payments";4;"Deleted
Jobs";5;"Deleted Parts";6;"Deleted Customers";7;"Deleted
Purchase";8;"Changed Inv. Status"
Case "Quote"
rs!LogAction = 1
Case "Invoice"
rs!LogAction = 2
Case "Payment"
rs!LogAction = 3
Case "Job"
rs!LogAction = 4
Case "Part"
rs!LogAction = 5
Case "Customer"
rs!LogAction = 6
Case "Purchase"
rs!LogAction = 7
Case "InvoiceStatus"
rs!LogAction = 8
End Select
rs!LogDesc = LogDesc
rs.Update
rs.Close
db.Close
Exit Function
ErrRtn:
MsgBox Err.Number & " - " & Err.Description & "Function: AuditLog",
vbCritical
Exit Function
End Function
.



Relevant Pages

  • Re: Oracle NULL vs revisited
    ... invoice identifier. ... function representung the string less its non-numeric characters. ... substitute for an unknown value. ...
    (comp.databases.oracle.server)
  • Re: jtds driver and SQL Server performance problem
    ... The slow query is retreiving the row based on a "char" column. ... } catch (SQLException e) ... invoice = checkInvoice; ... public void writeInvoice(int docid, int objectid, String invoice) ...
    (comp.lang.java.databases)
  • Re: help please! reading text re post
    ... Dim Buffer As String ... get stuff like invoice date, ... Declare 3 integer variable (e.g. posi As Integer, t As Integer, ...
    (microsoft.public.vb.general.discussion)
  • Re: Understanding Public Module or Class
    ... Public shared myPublic as String ... Dim Invoice As Decimal ... Dim Wage As Decimal ... problems if I have textboxes named the same in two diffrent forms? ...
    (microsoft.public.dotnet.general)