Skip Headers

Oracle® Objects for OLE Developer's Guide
10g Release 1 (10.1)

Part Number B10118-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Feedback

Commit_Click() Procedure (Add)

The Commit_Click() event procedure for adding records looks like:

Private Sub Commit_Click()

Dim DupDyn As Object

Dim DupDynQry As String

On Error GoTo err_commit

'Put all this into a function returning error code

'Check for NULLs

ErrMsg = ""

If txtEmpno = "" Then

ErrMsg = "You must enter a value for Employee Number"

Error 1

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

'Check for duplicate empno value by attempting to count rows with

'same value.

'Build Query

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 = "Empno already present!!!"

Error ErrNum

End If

'Add the new record to dynaset

EmpDynaset.AddNew

EmpDynaset.Fields("empno").Value = txtEmpno

EmpDynaset.Fields("ename").Value = txtEname

EmpDynaset.Fields("job").Value = txtJob

EmpDynaset.Fields("mgr").Value = txtManager

EmpDynaset.Fields("hiredate").Value = txtHireDate

EmpDynaset.Fields("sal").Value = txtSal

EmpDynaset.Fields("comm").Value = txtComm

EmpDynaset.Fields("deptno").Value = txtDepno

'Update the database

EmpDynaset.Update

Commit.Enabled = False

AddNew.Enabled = True

Exit Sub

err_commit:

If ErrMsg <> "" Then

MsgBox ErrMsg

Else

MsgBox Error$

End If

End Sub