Dim collQuery As String
On Error GoTo errConn
If collFindConn.State <> adstateclose Then collFindConn.Close
collFindConn.CursorLocation = adUseClient
collFindConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & App.Path & "\Data\studentFile.mdb;Persist Security Info=False"
collFindConn.Open
On Error GoTo errRecord
If Text3.Text = "" Then
MsgBox "查找项目不能为空!"
Else
collQuery = "select * from college where coll_name like '% " & Text3.Text & " % ' "
'collQuery = "select * from college"
If collFindRs.BOF = True Or collFindRs.EOF = True Then
MsgBox "数据" & Text3.Text & "没找到", vbExclamation, "注意"
Else
On Error GoTo errOther
collFindRs.Open collQuery, collFindConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = collFindRs
DataGrid1.Refresh
End If
End If
If collFindRs.State <> adstateclose Then collFindRs.Close
Exit Sub
errConn:
MsgBox "数据库连接错误:" & Err.Description, vbExclamation, "注意"
Exit Sub
errRecord:
MsgBox "collFindRs错误:" & Err.Description, vbExclamation, "注意"
collFindConn.Close
Exit Sub
errOther:
MsgBox "其他错误:" & Err.Description, vbExclamation, "注意"
collFindRs.Close
collFindConn.Close
Exit Sub
On Error GoTo errConn
If collFindConn.State <> adstateclose Then collFindConn.Close
collFindConn.CursorLocation = adUseClient
collFindConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & App.Path & "\Data\studentFile.mdb;Persist Security Info=False"
collFindConn.Open
On Error GoTo errRecord
If Text3.Text = "" Then
MsgBox "查找项目不能为空!"
Else
collQuery = "select * from college where coll_name like '% " & Text3.Text & " % ' "
'collQuery = "select * from college"
If collFindRs.BOF = True Or collFindRs.EOF = True Then
MsgBox "数据" & Text3.Text & "没找到", vbExclamation, "注意"
Else
On Error GoTo errOther
collFindRs.Open collQuery, collFindConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = collFindRs
DataGrid1.Refresh
End If
End If
If collFindRs.State <> adstateclose Then collFindRs.Close
Exit Sub
errConn:
MsgBox "数据库连接错误:" & Err.Description, vbExclamation, "注意"
Exit Sub
errRecord:
MsgBox "collFindRs错误:" & Err.Description, vbExclamation, "注意"
collFindConn.Close
Exit Sub
errOther:
MsgBox "其他错误:" & Err.Description, vbExclamation, "注意"
collFindRs.Close
collFindConn.Close
Exit Sub
第13行:应该是出错的地方了。collFindRs对象你还没有打开,起码我看不到它被打开!
On Error GoTo errRecord
If Len(Text3) = 0 Then
MsgBox "....."
Else
collQuery = "SELECT * FROM [college] WHERE coll_name LIKE '%" & Text3 & "%'"
collFindRs.Open collQuery, collFindConn, 1
.................
第21行:与第3行同一个错误
楼主先不要用错误处理,直接运行程序,然后看看出错的地方在哪行
先排除代码的笔误或漏写的错误,再用错误处理来捕捉其它异常错误
On Error GoTo errConn
If collFindConn.State <> adstateclose Then collFindConn.Close
collFindConn.CursorLocation = adUseClient
collFindConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & App.Path & "\Data\studentFile.mdb;Persist Security Info=False"
collFindConn.Open
On Error GoTo errRecord
If Text3.Text = "" Then
MsgBox "查找项目不能为空!"
Else
collQuery = "select * from college where coll_name like '% " & Text3.Text & " % ' "
'collQuery = "select * from college"
collFindRs.Open collQuery, collFindConn, adOpenDynamic, adLockOptimistic
If collFindRs.BOF = True Or collFindRs.EOF = True Then
MsgBox "数据" & Text3.Text & "没找到", vbExclamation, "注意"
Else
On Error GoTo errOther
'collFindRs.Open collQuery, collFindConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = collFindRs
DataGrid1.Refresh
End If
End If
If collFindRs.State <> adstateclose Then collFindRs.Close
Exit Sub
errConn:
MsgBox "数据库连接错误:" & Err.Description, vbExclamation, "注意"
Exit Sub
errRecord:
MsgBox "collFindRs错误:" & Err.Description, vbExclamation, "注意"
collFindConn.Close
Exit Sub
errOther:
MsgBox "其他错误:" & Err.Description, vbExclamation, "注意"
collFindRs.Close
collFindConn.Close
Exit Sub