Example: Object Validation

This example demonstrates how you can perform validations of all fields by using the CanPost event procedure. For example, this code segment ensures that a user cannot reject a defect without adding a comment.

In this example, a user may not post a defect where the defect status (BG_STATUS) has been changed to Rejected unless some explanatory text has been typed in the R&D Comment field (BG_DEV_COMMENTS).

Add the code to the Bug_CanPost event procedure so that the check is performed when the user attempts to submit the defect.

Function Bug_CanPost
        ' Initialize the function's return value 
	 ' to avoid unpredictable behavior.
        Bug_CanPost =  False 
        On Error Resume Next
        If Bug_Fields("BG_STATUS").IsModified and _
        Bug_Fields("BG_STATUS").Value = "Rejected" and _
        not Bug_Fields("BG_DEV_COMMENTS").IsModified then
            Bug_CanPost = False
            msgbox "You must enter a comment when rejecting a defect."
            Bug_CanPost = True
        End If
        PrintError "Bug_CanPost"
        On Error GoTo 0
End Function