473,586 Members | 2,620 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.certa in 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 2861
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
2504
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 to enable everything as a single event can generate multiple BIG records that will swamp the system. Going over the requirementat and our access...
2
1220
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 that has no border fully dragable... ie you can click and hold any where to move it around the desktop Thanks for any help inadvance
2
1481
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 of the screen. Basically, Detail Records are being added to a tblDetails, and then they show in the list box. The user can "delete" by...
3
3774
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 password entered.My case now is I have Audit Trail Module which keeps records of modifications and current user, I wanted my audit trail to log the...
2
1224
by: Blurbint | last post by:
Like, if i got 2 forms, then when form 2 is opend it changes form 1's backcolor?
1
1014
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 want different fields to appear. e.g. if I select Printer then it will have fields for "cartridge type" "number of trays" etc. and if I select...
2
2801
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 design GUI. however, if the forms appearance changes (form size, textbox size, number of buttons, etc), due to the users experience, how can i...
20
2696
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 background: This database will be used on a common computer, shared amongst the team members. Hence, I've created a login screen for users to login...
0
884
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 search in audit trail and now one search in normal search form. my search form dont work. i make new database and in the new is working. but it the...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.