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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,432
Messages
6,124,856
Members
449,194
Latest member
HellScout

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