当我键入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
答案 0 :(得分:1)
您需要在错误标签之前将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