On 15 Apr 2005 20:37:55 -0700,
pietlinden@hotmail.com wrote:
[color=blue]
>sure. pass all the data you want to another function that writes it to
>another table by opening a recordset and appending the data...
>
>public function LogOldAndNewValues( lngPID As Long, strForm as string,
>strField As String, varOldValue as Variant, varNewValue as Variant)
>dim rs as dao.recordset
>set rs=dbengine(0)(0).openrecordset("LogTable",dbopent able)
>rs.addnew
>rs.fields("PID")=lngPID
>rs.fields("FormName")=strForm
>rs.fields("OldValue")=varOldValue
>rs.Fields("NewValue")=varNewValue
>rs.update
>rs.close
>set rs=nothing
>
>end function[/color]
Hi--i took your function above and included it in the first function.
It works quite well but am haviung one problem. If the old value or
new value is null then a record is not being created. With the code
below it is creating an aurdit record for each control on my form--If
the oldvalue and new value are both null then I want to move to the
next control without creating an audit record for that control I can't
figure out where to put apropiate code--see below:
Dim MyForm As Form, C As control, xName As String
Dim strPatID As String
Dim strForm As String
Dim strField As String
Dim varOldValue As Variant
Dim varNewValue As Variant
Set MyForm = Screen.ActiveForm
SNIPPED OTHER STUFF
For Each C In MyForm.Controls
'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox
' If control was previously Null, do something
HERE IS WHERE I WANT TO CHECK FOR NULLS AND AND STILL CREATE RECORD
FOR CHANGES
If (IsNull(C.OldValue) Or C.OldValue = "") And (C.Value = ""
Or IsNull(C.Value)) Then
WANT TO MOVE TO NEXT CONTROL WITHOUT CREATING AUDIT RECORD
Else
If (IsNull(C.OldValue) Or C.OldValue = "") And (C.Value <> ""
Or Not IsNull(C.Value)) Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
varOldValue = 888
varNewValue = C.Value
ElseIf C.Value <> C.OldValue And (C.OldValue <> "" Or
Not IsNull(C.OldValue)) Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
varOldValue = C.OldValue
varNewValue = C.Value
End If
Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = DBEngine(0)(0).OpenRecordset("test", dbOpenTable)
rs.AddNew
rs.Fields("PatId") = strPatID
SNIPPED OTHER FIELDS ADDED
rs.Update
rs.Close
Set rs = Nothing
End If
End Select
Next C
End Function
THANKS
bob