我想查询上一条和下一条的记录,
以下是代码
但是运行之后呢:
结果老是某两条,
按几次,结果都一样,也不会提示:第一条记录了,
或者最后一条记录了。
是不是逻辑上有错误。
表名叫humaninfo高人指点
 Select Case Button.Key
        Case "last"
             Sql = "select * from humaninfo "
             Call RS_Open(Sql)
           If RS.BOF Then
              MsgBox "已经是第一个记录了", vbInformation, "提示"
              Exit Sub
           Else
             RS.MoveLast
           
             Text1.Text = "" & RS!cname
             Text5.Text = "" & RS!shortname
             Text2.Text = "" & RS!age
             Text3.Text = "" & RS!idnum
             Text4.Text = "" & RS!schoolname
             Combo2.Text = "" & RS!gender
             Combo3.Text = "" & RS!nationnality
             Combo4.Text = "" & RS!degrees
             Text6.Text = "" & RS!Major
             DTPicker1.Value = "" & RS!birthday
             Combo5.Text = "" & RS!marriage
             DTPicker2.Value = "" & RS!graduatetime
             Combo7.Text = "" & RS!deptname
             DTPicker3.Value = "" & RS!entertime
             Combo10.Text = "" & RS!Position
             Combo13.Text = "" & RS!positioncondition
             Text8.Text = "" & RS!worktime
             Text10.Text = "" & RS!homeaddress
             Text12.Text = "" & RS!nativeplace
             Text11.Text = "" & RS!phone
             Text13.Text = "" & RS!mobile
             Text14.Text = "" & RS!email
             Text15.Text = "" & RS!staycard
             Combo16.Text = "" & RS!bankname
             Text21.Text = "" & RS!salary
             Text18.Text = "" & RS!bankid
            End If
            RS.Close
            Set RS = Nothing
        Case "next"
             Sql = "select * from humaninfo "
             Call RS_Open(Sql)
           If RS.EOF Then
              MsgBox "已经是最后一个记录了", vbInformation, "提示"
              Exit Sub
           Else
             RS.MoveNext
             'Sql = "select * from humaninfo "
             'Call RS_Open(Sql)
             
             Text1.Text = "" & RS!cname
             Text5.Text = "" & RS!shortname
             Text2.Text = "" & RS!age
             Text3.Text = "" & RS!idnum
             Text4.Text = "" & RS!schoolname
             Combo2.Text = "" & RS!gender
             Combo3.Text = "" & RS!nationnality
             Combo4.Text = "" & RS!degrees
             Text6.Text = "" & RS!Major
             DTPicker1.Value = "" & RS!birthday
             Combo5.Text = "" & RS!marriage
             DTPicker2.Value = "" & RS!graduatetime
             Combo7.Text = "" & RS!deptname
             DTPicker3.Value = "" & RS!entertime
             Combo10.Text = "" & RS!Position
             Combo13.Text = "" & RS!positioncondition
             Text8.Text = "" & RS!worktime
             Text10.Text = "" & RS!homeaddress
             Text12.Text = "" & RS!nativeplace
             Text11.Text = "" & RS!phone
             Text13.Text = "" & RS!mobile
             Text14.Text = "" & RS!email
             Text15.Text = "" & RS!staycard
             Combo16.Text = "" & RS!bankname
             Text21.Text = "" & RS!salary
             Text18.Text = "" & RS!bankid
            End If
          rs.close
            set rs= nothing
         end select

解决方案 »

  1.   

    RS 定义为模块变量
    RS_Open 仅在 Form_Load 中调用一次,不释放 RS
      

  2.   

    是的,将记录集变量定义为模块级吧,不用每次都set nothing
      

  3.   

    在module里面已经定义了
    Public Sub RS_Open(strSQL As String)
        Set RS = New ADODB.Recordset
        RS.Open strSQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText
    End Sub
    但是怎么会查询不到上一条下一条的记录呢?跟在那里定义应该没关系的吧?
      

  4.   

    Call RS_Open(Sql)只执行一次!!!不然重执行一次,游标又回到最前面,始终如此!
      

  5.   

    在 form_load中定义后,这个问题是解决了,但是又出现新的问题,每次点击下一条或者上一条按钮,
    程序都会跳出“已经是最后一条记录了”或者“已经是第一条记录了”
    要点击第三次才可以出现想要的结果。
    而且多点击几次后,就会出现eof和bof同时为真的错误?