Is it possible to refer to a fieldname on ActiveForm?

Sniper-BoOyA-

Registered User.
Local time
Today, 05:08
Joined
Jun 15, 2010
Messages
204
Good Afternoon,

I am working on a logging function (to log changes made using forms). I got it almost figured out.

There's just one thing that i cant seem to figure out though. I am trying to log the value of a field, on the form that is active at that time.

Ive been playing with the following:

Dim FieldValue As String
...
....
FieldValue = Forms!ActiveForm!Fieldname.value
..
..
(Add string to table)
rs!Field = FieldValue

But i cant seem to work this one out....

Any ideas?

Ps. I am currently at home so i do not have the full code. I will post the full code of the Log-function as soon as i arrive at work.

Thanks!
 
"ActiveControl Property"
http://msdn.microsoft.com/en-us/library/office/aa223188(v=office.11).aspx

Is this what you are looking for?

Thenks mdlueck.

Doesn't this mean the field i would like to refer to has to be 'activated' though?
I use the ActiveControl property to get the old value and the new value.

I have been using the following function for quite some time now;

Code:
Public Function TrackChanges()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strCtl As String
Dim strReason As String
Form_ActivityMonitor.LastAction = Now()
If Not CurrentUser = "dinterenp" Then
    If Not Screen.ActiveControl.OldValue = Empty Then
        strReason = InputBox("Wat is de reden voor deze wijziging? (Max 40 tekens)")
    End If
strCtl = Screen.ActiveControl.Name
strSQL = "SELECT Audit.* FROM Audit;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.RecordCount > 0 Then rs.MoveLast
   With rs
   .AddNew
   rs!FormName = Screen.ActiveForm.Name
   rs!Veldnaam = strCtl
   rs!datum = Date
   rs!Tijd = Time()
   rs!labnr = Labnummer
   rs!OudeWaarde = Screen.ActiveControl.OldValue              
   rs!NieuweWaarde = Screen.ActiveControl.Value                
   rs!Gebruiker = fOSUserName                                        
   rs!LoggedIn = CurrentUser()
   rs!Computer = FindComputerName
   rs!Reason = strReason
   .Update
   End With
Set db = Nothing
Set rs = Nothing
End If
End Function

Everything works fine. What i am looking for now is to add the value of a field (a field that is named the same on every form) on whatever form is active.
 
Update : I figured it out

After messing around a bit i got it to work by using;

rs!labnr = Screen.ActiveForm![labnr]

Here is the full code of the function in case anyone needs it.

Code:
Public Function TrackChanges()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strCtl As String
Dim strReason As String
Dim Labnummer As String
Form_ActivityMonitor.LastAction = Now()
If Not CurrentUser = "dinterenp" Then
    If Not Screen.ActiveControl.OldValue = Empty Then
        strReason = InputBox("Wat is de reden voor deze wijziging? (Max 40 tekens)")
    End If
strCtl = Screen.ActiveControl.Name
strSQL = "SELECT Audit.* FROM Audit;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.RecordCount > 0 Then rs.MoveLast
   With rs
   .AddNew
   rs!FormName = Screen.ActiveForm.Name
   rs!Veldnaam = strCtl
   rs!datum = Date
   rs!Tijd = Time()
   rs!labnr = Screen.ActiveForm![labnr]
   rs!OudeWaarde = Screen.ActiveControl.OldValue
   rs!NieuweWaarde = Screen.ActiveControl.Value
   rs!Gebruiker = fOSUserName
   rs!LoggedIn = CurrentUser()
   rs!Computer = FindComputerName
   rs!Reason = strReason
   .Update
   End With
Set db = Nothing
Set rs = Nothing
End If
End Function

Cheers!
 

Users who are viewing this thread

Back
Top Bottom