HELLO,
I have a function that seems to be working well on a sinlge form if someone makes a change except for two things. First I need the code (below) to reflect the person's Windows username and not the DB login which comes up in all cases as ADMIN as we don't have passwords assigned to our database. How could the code below be changed reflect the persons Windows login versus the DB sign in? This is the code I am using... and I have seen Environ=("username") but I could not get it to work - I am very new to code.
The second question - is I could not get it to record with a sub-form situation - is there a way to do that? I can post my Database if that would be helpful.
Thank you for any help. I truly appreciate it.
LisaEllen
Function WriteChanges()
Dim f As Form
Dim c As Control
Dim frm As String
Dim user As String
Dim sql As String
Dim changes As String
Dim db As DAO.Database
Set f = Screen.ActiveForm
Set db = CurrentDb
frm = Screen.ActiveForm.Name
user = Application.CurrentUser
changes = ""
sql = "INSERT INTO AuditTrail " & _
"([FormName], [Username], [ChangesMade]) " & _
"VALUES ('" & frm & "', '" & user & "', "
For Each c In f.Controls
Select Case c.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
If IsNull(c.OldValue) And Not IsNull(c.Value) Then
changes = changes & _
c.Name & "--" & "BLANK" & "--" & c.Value & _
vbCrLf
ElseIf IsNull(c.Value) And Not IsNull(c.OldValue) Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & "BLANK" & _
vbCrLf
ElseIf c.Value <> c.OldValue Then
changes = changes & _
c.Name & "--" & c.OldValue & "--" & c.Value & _
vbCrLf
End If
End Select
Next c
sql = sql & "'" & changes & "');"
db.Execute sql, dbFailOnError
Set f = Nothing
Set db = Nothing
End Function