ErrorHandler 仍然显示错误
ErrorHandler still showing error
当我输入 text1 但它是错误的时,错误显示但 command2 已启用。当我输入正确的数据库名称时。错误仍然显示,command2 再次启用。我不知道发生了什么。
Private Sub Command1_Click()
conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & " ;Data Source=COM1\SQLEXPRESS;password= 123"
On Error GoTo err
command2.Enabled = True
err:
MsgBox "none"
Exit Sub
End Sub
您需要将 Exit Sub 移到错误标签之前,以便它在触发错误之前退出 运行。
Private Sub Command1_Click()
conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & " ;Data Source=COM1\SQLEXPRESS;password= 123"
If Text2.Text = "Valid Name" Then
Text2.Enabled = True
Else
MsgBox "none"
End If
End Sub
当我输入 text1 但它是错误的时,错误显示但 command2 已启用。当我输入正确的数据库名称时。错误仍然显示,command2 再次启用。我不知道发生了什么。
Private Sub Command1_Click()
conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & " ;Data Source=COM1\SQLEXPRESS;password= 123"
On Error GoTo err
command2.Enabled = True
err:
MsgBox "none"
Exit Sub
End Sub
您需要将 Exit Sub 移到错误标签之前,以便它在触发错误之前退出 运行。
Private Sub Command1_Click()
conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & " ;Data Source=COM1\SQLEXPRESS;password= 123"
If Text2.Text = "Valid Name" Then
Text2.Enabled = True
Else
MsgBox "none"
End If
End Sub