I need to record within a database the IP address of any user making a change to records or inputting new records together with the date of the change - can this be done?
I record user info when they input or change data via a form...
I forget where I found this, but it seems to work for me...
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?" = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
Exit Sub
End If
Let Me.Date_Update = Date
Let Me.User_Update = Environ$("UserName"
End If
If you click the link just above your name in the third post in this thread, RomanW1 will get a semi-official thanks, and it will go down on his (or her) personal record.
Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
To pickup and use the windows logon id:
Create a module called: vbAPI
Function GetUserID()
' RMO, 2/3/98
' API to get the Username from the Windows registry
Dim strName As String
Dim lngSize As Long
Dim lngRetVal As Long
lngSize = 199
strName = String(200, 0)
lngRetVal = GetUserName(strName, lngSize)
GetUserID = UCase(Left(strName, lngSize - 1))
End Function
On your form
add an expression for save or change or whatever and call the function
Howi: Do you need a full audit log, i.e., the table & field old & new values or just to keep track of who does generic DML (UPDATE & INSERT) along with the timestamp.
If you just need to keep track of who's changing data, rather than audit the changes themselves, you could use the form AfterUpdate and AfterInsert events to INSERT user,dml_type, and timestamp into a changes table.
Jeffrey R. Roberts
Insight Data Consulting
Access, SQL Server, & Oracle Development
Quehay - We just need to know who makes changes etc
RomanW1's code seems to do the trick although we have ammended a little to insert date and time of change, username and computer name to make tracking easier for us.
many thanks to all who replied to my request
What a fantastic group.
To each their own, as they say, and hte code used is just to return the UserID to the from control, so we do not see how it is used, but many soloutions only record the "latest" User ID (generally kept within the single record. This quickly becomes more-or-less useless in any but the most cosmetic sense, as you cannot say with any certanity that the reorded user may any specific change which may be the subject of contention. Your ammendment (to include the date/time of the change) suggests that you are attempting to use the info for other purposes.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.