[green]
'********************
'* §lamKeys §oftware® (mailto: programmer@coder.org)
'*
'* @CREATED : 1/12/2005 4:01:54 PM
'* @PARAMS : strControlName - the name of the control.
'* @RETURNS : True if the control's value is not equal
'* : to its OldValue, False otherwise.
'* @NOTES : Null controls don't have an OldValue.
'* : This function must reside in the form
'* : module containing the controls.
'* @USAGE : =HasChanged("Text1")
'********************[/green]
Function HasChanged(ByVal strControlName As String) As Boolean
On Error GoTo ErrHandler
Dim strVal As String
Dim ctl As Object
[green]'Attempt to reference the control
'using the argument passed in. If
'an error occurs, the control doesn't
'exist and execution will jump to the label
'named 'ErrHandler:'[/green]
Set ctl = Me.Controls(strControlName)
[green]'Since some controls may not have an OldValue,
'we're anticipating errors, so resume when that
'happens and check the Err.Number to see what
'happened.[/green]
On Error Resume Next
strVal = ctl.OldValue
If Err.Number = 0 Then
[green]'If we get here, no error occurred, so let's
'compare the control's current value with its
'OldValue. If they aren't equal, then set the
'function's value to True for the return value.
'If they are equal, we do nothing because the
'function will return False by default.[/green]
If ctl.Value <> ctl.OldValue Then
HasChanged = True
End If
End If
ExitHere:
[green]'This is the normal exit to the function[/green]
Exit Function
ErrHandler:
[green]'The only way this code will execute is if an error
'occurs before we set the 'On Error Resume Next'
'statement, which could happen when we try to
'reference the control in the first step.[/green]
Debug.Print Err, Err.Description
[green]'This line clears the error and continues code
'execution at the 'ExitHere:' label, ending
'the function.[/green]
Resume ExitHere
End Function