Oracle Objects for OLE
Release 9.2

Part Number A95895-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents

Master Index

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


 
Oracle
Copyright © 1994, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents

Master Index

Feedback