I have written the following code for VB6
The application uses MS Access and used Microsoft Jet 4.0 OLEDM Provider
Private Sub cmdSubmit_Click()
On Error GoTo Handler
Eval_Env.Insert txtEvalCode.Text, txtEvalName.Text, txtEvalPhone.Text, 0
ClearControls
Label4.Caption = "Data Submitted Successfully"
Label4.Visible = True
Handler:
MsgBox "An error occurred"
Label4.Visible = False
Exit Sub
End Sub
Private Sub ClearControls()
txtEvalName.Text = ""
txtEvalCode.Text = ""
txtEvalPhone.Text = ""
txtEvalCode.SetFocus
End Sub
Private Sub txtEvalPhone_Validate(Cancel As Boolean)
If Not IsNumeric(txtEvalPhone.Text) Then
txtEvalPhone.Text = ""
Cancel = True
End If
End Sub
When I run this, after submitting(click event of the command button) the above code gives msg "an error occurred" and then executes executes Label4.Visible = False.
But still the data is entered into the database.
The msgbox appears whether I give correct values in textboxes or wrong/incompatible values in the txtboxes. How to solve this ?
Although Database is updated only in case correct values r given.