Oracle® Objects for OLE Developer's Guide 10g Release 1 (10.1) Part Number B10118-01 |
|
The function DoValidationChecks() returns True if the entered data is valid; otherwise it returns False.
Function DoValidationChecks() As Boolean
Dim DupDyn As Object
Dim DupDynQry As String
On Error GoTo err_ValidationCheck
ErrMsg = ""
'Empno cannot be changed while in Update mode, so we can skip over validation
If DoAdd Then
If txtEmpno = "" Then
ErrMsg = "You must enter a value for Employee Number"
Error 1
End If
End If
If txtHireDate <> "" And Not IsDate(txtHireDate) Then
ErrMsg = "Enter date as dd-mmm-yy."
Error 2
End If
If txtDeptno = "" Then
ErrMsg = "You must enter a value for Department Number"
Error 3
End If
'If adding a record, check for Duplicate empno value by
'attempting to count rows with same value
'Build Query:
If DoAdd Then
DupDynQry = "select count(*) from emp where empno = " & txtEmpno
Set DupDyn = OraDatabase.CreateDynaset(DupDynQry, ORADYN_NOCACHE)
If DupDyn.Fields(0).Value <> 0 Then
ErrNum = DUPLICATE_KEY
ErrMsg = "Employee Number already exists."
Error ErrNum
End If
End If
'Succesful validation with no errors returns True
DoValidationChecks = True
Exit Function
err_ValidationCheck:
If ErrMsg <> "" Then
MsgBox ErrMsg
Else
MsgBox Error$
End If
'Validation returns false on failure
DoValidationChecks = False
End Function