dewsbury
08-21-2008, 02:46 AM
Be gentle with me - I am no guru!
I am trying to use a piece of code that checks to see if a user has mades changes on my form.
The code work fine except for where a field previously held no value.
In this case nothing is found.
I have tried
If C.OldValue = Null Or C.OldValue = ""
I have also tried;
If len(C.OldValue) = 0
None of these seem to trap a field that is simply blank.
The rest of the code is working okay.
How can I detect such a field?
==============================================
See code below which was copied from web;
(See *********** for problematic bit).
Option Compare Database
Option Explicit
Function AuditTrail()
On Error GoTo Err_Handler
Dim MyForm As Form, C As Control, xName As String, Tempp As String, DateTimeStr As String
Set MyForm = Screen.ActiveForm
'Set date and current user if form has been updated.
DateTimeStr = " " & Date & " " & Time & " by " & CurrentUser() & " -> "
'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"New Record """
End If
'Check each data entry control for change and record
'old value of Control.
For Each C In MyForm.Controls
'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
' Skip Updates field.
If C.Name <> "Updates" Then
' ******************************
If C.OldValue = Null Or C.OldValue = "" Then
MsgBox ("found blank")
MyForm!Updates = Chr(13) & Chr(10) & _
C.Name & " Changed From : Blank Changed To: " & C.Value & MyForm!Updates
MyForm!Last_update = Date
' If control had previous value, record previous value.
ElseIf IIf(IsNull(C.Value), "", C.Value) <> C.OldValue Then
MyForm!Updates = Chr(13) & Chr(10) & _
DateTimeStr & C.Name & " OLD: " & C.OldValue & " NEW: " & C.Value & MyForm!Updates
MyForm!Last_update = Date
End If
End If
End Select
Next C
TryNextC:
Exit Function
Err_Handler:
If Err.Number <> 64535 Then
MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description
End If
Resume TryNextC
End Function
I am trying to use a piece of code that checks to see if a user has mades changes on my form.
The code work fine except for where a field previously held no value.
In this case nothing is found.
I have tried
If C.OldValue = Null Or C.OldValue = ""
I have also tried;
If len(C.OldValue) = 0
None of these seem to trap a field that is simply blank.
The rest of the code is working okay.
How can I detect such a field?
==============================================
See code below which was copied from web;
(See *********** for problematic bit).
Option Compare Database
Option Explicit
Function AuditTrail()
On Error GoTo Err_Handler
Dim MyForm As Form, C As Control, xName As String, Tempp As String, DateTimeStr As String
Set MyForm = Screen.ActiveForm
'Set date and current user if form has been updated.
DateTimeStr = " " & Date & " " & Time & " by " & CurrentUser() & " -> "
'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"New Record """
End If
'Check each data entry control for change and record
'old value of Control.
For Each C In MyForm.Controls
'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
' Skip Updates field.
If C.Name <> "Updates" Then
' ******************************
If C.OldValue = Null Or C.OldValue = "" Then
MsgBox ("found blank")
MyForm!Updates = Chr(13) & Chr(10) & _
C.Name & " Changed From : Blank Changed To: " & C.Value & MyForm!Updates
MyForm!Last_update = Date
' If control had previous value, record previous value.
ElseIf IIf(IsNull(C.Value), "", C.Value) <> C.OldValue Then
MyForm!Updates = Chr(13) & Chr(10) & _
DateTimeStr & C.Name & " OLD: " & C.OldValue & " NEW: " & C.Value & MyForm!Updates
MyForm!Last_update = Date
End If
End If
End Select
Next C
TryNextC:
Exit Function
Err_Handler:
If Err.Number <> 64535 Then
MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description
End If
Resume TryNextC
End Function