Guys, do you have any idea about error trapping in save and handling using the ibm database program .im using the vb to manipulate ibm database program...
Guys, do you have any idea about error trapping in save and handling using the ibm database program .im using the vb to manipulate ibm database program...
defaultButtons
On Error GoTo errSave
'On Error Resume Next
Dim sqlstr As String
Dim rs As ADODB.Recordset
If NewEdit = "" Then
rs.Open " select * from employee where empno ='" & txtEmpNum & "'"
'If txtEmpNum.Text = " " Then
'MsgBox " DON'T LEAVE IT BLANK"
'
If rs.EOF Then
'Exit Sub
If NewEdit = 1 Then
db2Conn.BeginTrans
db2Conn.Execute "INSERT INTO Employee(EMPNO,FIRSTNME,MIDINIT,LASTNAME,WORKDEPT, PHONENO,HIREDATE,JOB,EDLEVEL,***,BIRTHDATE,SALARY, BONUS,COMM) VALUES ('" & txtEmpNum.Text & "','" & txtFirstNme.Text & "','" & txtMidinit.Text & "','" & txtLastName.Text & "','" & txtWorkdept.Text & "','" & txtPHONENO.Text & "', '" & DTHIREDATE.Value & "','" & txtJOB.Text & "'," & Val(txtEdlevel.Text) & ",'" & TXTSEX.Text & "','" & BDATE.Value & "'," & Val(txtSalary.Text) & ", " & Val(txtBONUS.Text) & "," & Val(txtCOMM.Text) & ")"
MsgBox "RECORD SUCCESSFULLY SAVED"
Exit Sub
Else
MsgBox "Duplicate Stock Code. Please review your entries!!", vbCritical, Me.Caption
End If
Else
db2Conn.Execute "UPDATE employee set firstnme = '" & Left(txtFirstNme.Text, 12) & "',midinit = '" & Left(txtMidinit.Text, 1) & "',lastname = '" & Left(txtLastName.Text, 15) & "', workdept = '" & Left(txtWorkdept.Text, 3) & "',Phoneno = '" & Left(txtPHONENO.Text, 4) & "',HIREDATE = '" & DTHIREDATE.Value & "', JOB = '" & Left(txtJOB.Text, & "',EDLEVEL = " & Val(txtEdlevel.Text) & " , *** = '" & TXTSEX.Text & "' , BIRTHDATE= '" & BDATE.Value & "', SALARY = " & Val(txtSalary.Text) & ", BONUS = " & Val(txtBONUS.Text) & ", COMM = " & Val(txtCOMM.Text) & " where empno = '" & txtEmpNum.Text & "'"
MsgBox "SUCCESSFULLY UPDATED"
Exit Sub
End If
End If
db2Conn.CommitTrans
clearTxt
errExit:
Exit Sub
errSave:
db2Conn.RollbackTrans
MsgBox Err.Description, vbCritical, "ERROR:" & Me.Caption
Resume errExit
cmdSave.Enabled = True
cmdNew.Enabled = False
cmdDelete.Enabled = False
cmdEdit.Enabled = False
defaultButtons
On Error GoTo errSave
Dim sqlstr As String
Dim rs As ADODB.Recordset
If len(txtEmpNum.Text)=0 Then
MsgBox " DON'T LEAVE IT BLANK"
Exit Sub
End If
If NewEdit = "" Then
rs.Open " select * from employee where empno ='" & txtEmpNum & "'"
If rs.EOF Then
If NewEdit = 1 Then
db2Conn.BeginTrans
db2Conn.Execute "INSERT INTO Employee(EMPNO,FIRSTNME,MIDINIT,LASTNAME,WORKDEPT, PHONENO,HIREDATE,JOB,EDLEVEL,***,BIRTHDATE,SALARY, BONUS,COMM) VALUES ('" & txtEmpNum.Text & "','" & txtFirstNme.Text & "','" & txtMidinit.Text & "','" & txtLastName.Text & "','" & txtWorkdept.Text & "','" & txtPHONENO.Text & "', '" & DTHIREDATE.Value & "','" & txtJOB.Text & "'," & Val(txtEdlevel.Text) & ",'" & TXTSEX.Text & "','" & BDATE.Value & "'," & Val(txtSalary.Text) & ", " & Val(txtBONUS.Text) & "," & Val(txtCOMM.Text) & ")"
MsgBox "RECORD SUCCESSFULLY SAVED"
Else
MsgBox "Duplicate Stock Code. Please review your entries!!", vbCritical, Me.Caption
End If
Else
db2Conn.Execute "UPDATE employee set firstnme = '" & Left(txtFirstNme.Text, 12) & "',midinit = '" & Left(txtMidinit.Text, 1) & "',lastname = '" & Left(txtLastName.Text, 15) & "', workdept = '" & Left(txtWorkdept.Text, 3) & "',Phoneno = '" & Left(txtPHONENO.Text, 4) & "',HIREDATE = '" & DTHIREDATE.Value & "', JOB = '" & Left(txtJOB.Text, & "',EDLEVEL = " & Val(txtEdlevel.Text) & " , *** = '" & TXTSEX.Text & "' , BIRTHDATE= '" & BDATE.Value & "', SALARY = " & Val(txtSalary.Text) & ", BONUS = " & Val(txtBONUS.Text) & ", COMM = " & Val(txtCOMM.Text) & " where empno = '" & txtEmpNum.Text & "'"
MsgBox "SUCCESSFULLY UPDATED"
End If
End If
db2Conn.CommitTrans
clearTxt
errExit:
rs.close
Set rs=nothing
Exit Sub
errSave:
db2Conn.RollbackTrans
MsgBox Err.Description, vbCritical, "ERROR:" & Me.Caption
Resume errExit
cmdSave.Enabled = True
cmdNew.Enabled = False
cmdDelete.Enabled = False
cmdEdit.Enabled = False
''----------------------------------------------------
''just modify your code..
''remove exit sub after the 2 messagebox so that
db2Conn.CommitTrans
ClearTxt
''will be executed by the program..
''try to check your Insert Into and Update statement..
''happy coding..
no active g hapon transaction bro...then ika human object not declared daw?
Similar Threads |
|