I believe the following code might be what you have in mind.
Below is an older example of code from HP for some custom workflow code. The code is pretty simple so should be too hard at all to adapt to your setup.
The below features BG_USER_03 for the UDF in question, but you can obviously put in whatever UDF you are working with.
In the Bug_FieldChange subroutine, it checks whether the user types in between 15-30 characters. If not, it returns an error message and resets the value to what it originally was. The LastValue function is a utility function that returns the original value of the field before any changes were made.
Example:
Sub Bug_New
End Sub
Sub Bug_FieldChange (FieldName)
' Check the length of the string that the user types in BG_USER_03.
' If the length is not between 15 to 30 characters, return an error message and
' switch back the value to what it originally was.
if FieldName = ''BG_USER_03'' and (Len(Fields(''BG_USER_03'').Value)<15 or Len(Fields(''BG_USER_03'').Value)>30) then
MsgBox ''This field should be between 15 to 30 characters long!''
Fields(''BG_USER_03'').Value = LastValue(''BG_USER_03'')
end if
End Sub
Sub Bug_MoveTo
End Sub
Function Bug_CanPost
End Function
Function LastValue(FieldName)
'This function returns the value of the field before the user changes it.
'FieldName - name of field you are looking for
dim com
dim rec
dim td
'If the bug is new then the previous value is Null
if fields(''BG_BUG_ID'').IsNull then LastValue =''''
exit function
end if
set td = TDConnection
set com = td.Command
com.CommandText = ''select '' & FieldName & '' from BUG where BG_BUG_ID='' &Fields(''BG_BUG_ID'').Value
set rec = com.Execute
rec.First
LastValue = rec.FieldValue(Cstr(FieldName))
set com = nothing
set rec = nothing
End Function