在浏览网页寻找答案后,我看到了这个解释 VB6 中的错误处理的网站。
我现在终于可以继续前进了。这是代码:
On Error GoTo err_CmdAdd_Click
con.Open _
"Provider = sqloledb;" & _
"Data Source=server;" & _
"Initial Catalog=database;" & _
"User ID=username;" & _
"Password=password;"
If img_edit.BorderStyle = 1 Then
Set rs = con.Execute("insert into a_owner values('" & txt_unit.Text & "', " _
& " '" & txt_tower.Text & "' )")
MsgBox "Record added successfully...", vbInformation
ado1.Refresh
exit_err_CmdAdd_Click:
Exit Sub
err_CmdAdd_Click:
MsgBox "Duplicate Record!", vbCritical, "Duplicate"
txt_unit.Text = ""
txt_unit.SetFocus
End If