You can make changes to his code. If, for example, your table has two fields
as its key (a text field and a numeric field), you can change AuditDelBegin
from
Function AuditDelBegin(sTable As String, sAudTmpTable As String, _
sKeyField As String, lngKeyValue As Long) As Boolean
Dim db As DAO.Database ' Current database
Dim sSQL As String ' Append query.
' Append record to the temp audit table.
Set db = DBEngine(0)(0)
sSQL = "INSERT INTO " & sAudTmpTable & _
" ( audType, audDate, audUser ) " & _
"SELECT 'Delete' AS Expr1, Now() AS Expr2, " & _
"NetworkUserName() AS Expr3, " & sTable & ".* " & _
"FROM " & sTable & " WHERE (" & sTable & "." & _
sKeyField & " = " & lngKeyValue & ");"
db.Execute sSQL, dbFailOnError
End Function
to
Function AuditDelBegin(sTable As String, sAudTmpTable As String, _
sKeyField1 As String, sKeyValue1 As String,
sKeyField2 As String, lngKeyValue2 As Long) As Boolean
Dim db As DAO.Database ' Current database
Dim sSQL As String ' Append query.
' Append record to the temp audit table.
Set db = DBEngine(0)(0)
sSQL = "INSERT INTO " & sAudTmpTable & _
" ( audType, audDate, audUser ) " & _
"SELECT 'Delete' AS Expr1, Now() AS Expr2, " & _
"NetworkUserName() AS Expr3, " & sTable & ".* " & _
"FROM " & sTable & " WHERE (" & sTable & "." & _
sKeyField1 & " = '" & sKeyValue1 & "' AND " & _
sTable & "." & sKeyField2 & " = " & lngKeyValue2 & ");"
db.Execute sSQL, dbFailOnError
End Function
and then change how you call it from
Call AuditDelBegin("tblInvoice", "audTmpInvoice", _
"InvoiceID", Nz(Me.InvoiceID,0))
to
Call AuditDelBegin("tblInvoice", "audTmpInvoice", _
"CustomerNm", Nz(Me.Customer,"")), _
"InvoiceID", Nz(Me.InvoiceID,0))
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Belinda" <(E-Mail Removed)> wrote in message
news:14023775-70E0-468E-990D-(E-Mail Removed)...
> Allen's code end result is exactly what I need as well, except one that my
> database does not meet the #1 condition, i.e., "each table to be audited
must
> have an AutoNumber primary key"
>
> Is there a way around that?
>
> "Douglas J. Steele" wrote:
>
> > Take a look at what Allen Browne has at
> > http://members.iinet.net.au/~allenbrowne/AppAudit.html
> >
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no e-mails, please!)
> >
> >
> >
> > "Paul B." <(E-Mail Removed)> wrote in message
> > news:9087EA6B-A6B1-4386-A339-(E-Mail Removed)...
> > > Can someone give me an idea of how best to build an audit trail?
> > >
> > > I have built my first two databases, mostly using exmaples and help
from
> > the
> > > good people that answer questions here, and now that I have sort of an
> > audit
> > > trail, it appears to me that there must be a better way.
> > >
> > > I have several forms that write to one or more tables. Call it a lack
of
> > > design forethought, however, now that I look at it, I am wondering if
I
> > could
> > > have one table act as the audit trail, maybe tying the
Row#(autonumber)
> > and
> > > table name to the data row in the audit trail table.
> > >
> > > I am asking to see if I have the time or energy to modify my database
> > before
> > > putting it online for trials.
> > >
> > > Cheers
> > >
> >
> >
> >