Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very Important!!!!Log File 2

Status
Not open for further replies.

nycdata

Programmer
Jun 28, 2004
26
US

I need to create a log file for an access database.

Should i create a log table and/or log file??

Any kind of help will be greatly appreciated!!!
 
If you have a DB anyway, then why not use it. Although either would be almost as good as the other, IMO.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
nycdata

How are you going to access the log?

If only from outside of Access, then use the text log file. The bummer is that it will append to the end of the file, and you would want to look at the most recent info at the top of the file. (You could get fancy with the DOS COPY command file to get around this and place the most recent data on top. But still not as good as the TAIL command in Unix)

If you are going to use Access to access the log, then use a table. Much superior reporting and control abilities. Print a monthly report, look at stats for every Monday, sort by Department, etc.

Richard
 
Can i get an idea of tracking log through a table??
 
nycdata

There are numerous ways -- see forums and FAQs and review books, but here is a starter...

Best to create a module for this. The module can be called from anywhere - reports, menu items, forms, data changes, etc.

Call the module anytime you want to trap your data.

Key things...
CurrentUser - gives you the name of the current user. (Will be Admin if you do not have security implemented)
Now() gives you date + time, and Date() gives you the current date.
Me.Form.Name gives you name of current form.

Untested coding example...
Code:
Function AuditNYC (strAction as String, strForm as String, strID as String, strSQL as String) as Boolean

Dim dbs as DAO.Database, rst as DAO.RecordSet

Set dbs = CurrentDB()
Set rst = dbs.OpenRecordSet("YourAuditTable")

With rst
    .AddNew
    !User = CurrentUser
    !AuditDate = Now()
    !FormName = strForm
    !Action = strAction
    !UniqueID = strID
    !RecordSource = strSQL
    .Update
End With

rst.close
dbs.close

AuditNYC = True

End Fucntion

And call the function, for example after adding a new record...

Code:
'Code in AfterUpdate record event, not field event
Dim strAction as String, strForm as String, strID as String, strSQL as String

strAction = "AddNew"
strForm = Me.Form.Name
strSQL = Me.RecordSource
strID = Format(Me.YourID, "0")

If Not AuditNYC (strAction, strForm, strID, strSQL) 
   MsgBox "Audit failed"
End If

There is far better code out there in the wild.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top