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.

Recommended Answers

All 2 Replies

A typical error handler goes something like this...

Private Sub Command1_Click(Index As Integer)

On Error GoTo Command1_ClickError

Exit Sub
Command1_ClickError:

End Sub

Now, looking at your code I can see you have the exit sub after the msgbox and not before the error handler label....

Good Luck

thanx
it wrkd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.