各位大侠,我遇到了一个奇怪的问题????
我写了一个标准模块,在main内声明打开了连接和记录集,并在form1中调用。当我向form1的文本框赋值时提示一下错误信息:
实时错误 ‘3021’:
BOF 或 EOF中有一个是“真”,或者当前的记录已经删除,所需的操作要求一个当前的记录。
请帮忙给看看吧!!!! ^_^
/**************************
* 这是标准模块中的代码 *
**************************/
Option Explicit
Public conn As New ADODB.Connection
Public Ress As New ADODB.Recordset
Public Ress2 As New ADODB.Recordset
Private Sub main()
conn = "Provider=SQLOLEDB.1;Password=*******;Persist Security Info=True;User ID=sa;Initial Catalog=newmark;Data
Source=SUNFLOWER"
conn.Open
Ress.Open "test", conn, adOpenKeyset, adLockPessimistic
form1.Show
End Sub
Public Sub close_conn()
conn.Close
End Sub
/***************************
* 这是form1中的代码 *
***************************/
Private Sub command1_Click()
Dim into_val As String
Dim find_str As String
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
into_val = InputBox("请输入要查找的一卡通卡号", "精确查找")
If into_val = Empty Then
MsgBox "查询条件不能为空!!!!"
into_val = InputBox("请输入要查找的一卡通卡号", "精确查找")
End If
find_str = "select * from huiyuanxinxi where cuno='into_cal' ;"
Ress2.Open find_str, conn, adOpenKeyset, adLockPessimistic
If Ress.EOF And Ress.BOF Then
MsgBox "invalid couresid", vbOKOnly, "stop!!!"
Exit Sub
End If
/*******************************
* 问题出现在下面的赋值部分 *
*******************************/
Text1.Text = Ress2.Fields("aaa")
Text2.Text = Ress2.Fields("bbb")
Text3.Text = Ress2.Fields("ccc")
Ress.MoveNext
If Ress.EOF Then
Ress.MoveFirst
End If
Call close_conn
end sub