Access - Write to an audit log

Pumpk1n

Board Regular
Joined
Jan 31, 2017
Messages
86
Office Version
  1. 365
Platform
  1. Windows
I have a database called "Vendor" in which I need to track who has 'clicked' buttons to perform an event. The table is called "Audit Log" and I'm stuck on how to write the code to insert into a table. Here's what I have so far but I'm having issues on the "Insert" function. Can you help? I've "borrowed" the code and am not able to figure out how to troubleshoot. Thanks in advance!


Private Sub Command505_Click()
Dim strLocation As String
Dim db As DAO.Database
Dim sql As String
Set db = CurrentDb()
Me.Modified_by = Environ("USERNAME")
Me.Modified_on = Format(Now(), "yyyy-MM-dd hh:mm:ss")
sql = "Insert into AuditLog Values('" & Modified_by & "', '" & Modified_on & "', '" "NegativeBalance"');"
db.Execute sql
End Sub
 
You're also missing the quote prior to the Insert command.
Code:
sql = "Insert into AuditLog (modified_by, Modified_on) Values('" & Me.Modified_by & "', '" & Me.Modified_on & "', '" & NegativeBalance & "');" [COLOR=#B22222]Debug.Print sql[/COLOR]
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top