473,509 Members | 8,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to audit changes to a form

5 New Member
I have an access database for employees.certain users from manager level has access to this databse. I want to log any changes (add new,edit,delete) to the databse using vba code.the users will be using forms to do the edits. I have tried using the below code,but the problem is that the below code works only for a standalone form. My forms contain sub forms and navigation forms.
Oct 1 '20 #1
2 2854
muneermohd9690
5 New Member
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Public Function auditchanges(recordid As String, useraction As String)
  4. On Error GoTo auditerror
  5. Dim DB As Database
  6. Dim rst As Recordset
  7. Dim clt As Control
  8.  
  9. Set DB = CurrentDb
  10. Set rst = DB.OpenRecordset("select * from audittrail", adOpenDynamic)
  11. userlogin = getuserlogon()
  12. Select Case useraction
  13.     Case "new"
  14.         With rst
  15.             .AddNew
  16.             ![DateTime] = Now()
  17.             ![username] = userlogin
  18.             ![FormName] = Screen.ActiveForm.Name
  19.             '![FormName] = Screen.ActiveForm.ActiveControl.Name
  20.             ![Action] = useraction
  21.             ![recordid] = Screen.ActiveForm.Controls(recordid).Value
  22.             .Update
  23.         End With
  24.  
  25.     Case "delete"
  26.         With rst
  27.             .AddNew
  28.             ![DateTime] = Now()
  29.             ![username] = userlogin
  30.             ![FormName] = Screen.ActiveForm.Name
  31.             '![FormName] = Screen.ActiveForm.ActiveControl.Name
  32.             ![Action] = useraction
  33.             ![recordid] = Screen.ActiveForm.Controls(recordid).Value
  34.             .Update
  35.         End With
  36.  
  37.     Case "edit"
  38.          'For Each clt In Screen.ActiveForm.Controls
  39.          For Each clt In Screen.ActiveForm.ActiveControl.Form
  40.             If (clt.ControlType = acTextBox Or clt.ControlType = acComboBox) Then
  41.                 If Nz(clt.Value) <> Nz(clt.OldValue) Then
  42.                     With rst
  43.                         .AddNew
  44.                         ![DateTime] = Now()
  45.                         ![username] = userlogin
  46.                         '![FormName] = Screen.ActiveForm.Name
  47.                         ![FormName] = Screen.ActiveForm.ActiveControl.Form.Name
  48.                         ![Action] = useraction
  49.                         '![recordid] = Screen.ActiveForm.Controls(recordid).Value
  50.                         '![recordid] = Screen.ActiveForm.ActiveControl.Form(recordid).Value
  51.                         ![recordid] = Screen.ActiveForm.ActiveControl.Form(recordid).Value
  52.                         ![FieldName] = clt.ControlSource
  53.                         ![OldValue] = clt.OldValue
  54.                         ![NewValue] = clt.Value
  55.                         .Update
  56.                     End With
  57.                 End If
  58.              End If
  59.         Next clt
  60.  
  61. End Select
  62. rst.Close
  63. DB.Close
  64. Set rst = Nothing
  65. Set DB = Nothing
  66. auditerror:
  67.     'MsgBox Err.Number & ":" & Err.Description, vbCritical, "Error"
  68.     Exit Function
  69.  
  70. End Function
  71.  
  72.  
Oct 1 '20 #2
muneermohd9690
5 New Member
link to download the database

https://www.dropbox.com/s/kaw7j17bhe...111.accdb?dl=0
Oct 1 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2499
by: Byrocat | last post by:
We're going to be enabling the audit facility on some of our DB2 servers in the future, and I need some basic information on how large I can expect the log to grow. I've already been warning NOT...
2
1217
by: Stewart | last post by:
2 questions 1. How do i set the whole form's opacity prop? Right now i have to set an event handler for each element on the form. Is there are better way to do this? 2. how do i make a form...
2
1474
by: sara | last post by:
I have used Allen Browne's Audit Trail quite successfully. I now have an application where I have the user enter data on the top of the screen, and then put that data into a list box at the bottom...
3
3768
by: hary08 | last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and...
2
1222
by: Blurbint | last post by:
Like, if i got 2 forms, then when form 2 is opend it changes form 1's backcolor?
1
1011
by: Rozy | last post by:
Hi, I've created a database for and IT support company. I want the main support form to have a drop down list so it asks either "laptop, printer, server" etc. Depending on the answer i select i...
2
2799
by: forest demon | last post by:
in the VS designer, i can use the Format menu item to align, center in form, etc, etc.... so for example, if i have two or three buttons and some textboxes, i can align, or whatever, using the...
20
2672
by: Bellina | last post by:
Hi, My knowledge in Access is very limited but I have managed to build a pretty good-wroking database for my department based on help and assistance of experts from forums like this one. A bit of...
0
882
elenaA
by: elenaA | last post by:
hello Is posible becouse I have and audit trail and combo boxes which use search criteria to search audit changes now my new search form who also have search criteria does not work? i have one...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.