How to select current field for module Call?! (1 Viewer)

mattkorguk

Registered User.
Local time
Today, 00:48
Joined
Jun 26, 2007
Messages
301
Hi,
I'm trying to monitor a few fields and record who updated them together with the old and new values, so far, I have this;
This does work ok, I was just wondering if there's a way of refering to the current field, rather than having to specify 'me.NPW.oldvalue' etc.
Cheers
Matt
Code:
Private Sub NPW_AfterUpdate()
        Call LogFieldUpdate(Me.AppNumber, "NPW", Me.NPW.OldValue, Me.NPW)
End Sub
Code:
Public Function LogFieldUpdate(appNo As Long, fldName As String, oValue As String, nValue As String)
   ' Purpose:   Log updates to selected fields to track who is updating.
   
   Dim db As DAO.Database
   Dim tdf As DAO.TableDef
   Dim fld As DAO.Field
   Dim fldSQL As String
   
   Set db = CurrentDb()
                 
              fldSQL = "INSERT INTO _FieldUpdates ( AppNo, oFieldValue, nFieldValue, FieldName, UserName ) " _
                    & "SELECT " & appNo & ", " & Format(oValue, "ddmmyyyy") & ", " & Format(nValue, "ddmmyyyy") & ", '" & fldName & "', '" & [Forms]![switchboard].[UserName] _
                    & "';"
    
        DoCmd.SetWarnings False
            DoCmd.RunSQL fldSQL
        DoCmd.SetWarnings True
        
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:48
Joined
Aug 30, 2003
Messages
36,127
See if Screen.ActiveControl works for you.
 

mattkorguk

Registered User.
Local time
Today, 00:48
Joined
Jun 26, 2007
Messages
301
:D
I knew there must have been something in there to do the job!
Thank you very much.
Code:
Call LogFieldUpdate(Me.AppNumber, Screen.ActiveControl.Name, Screen.ActiveControl.OldValue, Screen.ActiveControl)
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:48
Joined
Aug 30, 2003
Messages
36,127
Happy to help!
 

Users who are viewing this thread

Top Bottom