为什么不用 data1.Recordset.AbsolutePosition ?

解决方案 »

  1.   

     Me.Data1.Caption = "第" & Data1.Recordset.AbsolutePosition & "条记录"
    可是我按“移至最后一个按钮”后,显示的是第0条记录
      

  2.   

    'BeginAbsolutePositionVB    'To integrate this code
        'replace the data source and initial catalog values
        'in the connection string
        
    Public Sub AbsolutePositionX()    'recordset and connection variables
    Dim rstEmployees As ADODB.Recordset
    Dim Cnxn As ADODB.Connection
    Dim strCnxn As String
    Dim strSQL As String
        'record variables
    Dim strMessage As String
        
        'Open connection
        Set Cnxn = New ADODB.Connection
        strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=;"
        Cnxn.Open strCnxn   strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
       ' Open Employee recordset with
       ' Client-side cursor to enable AbsolutePosition property
       Set rstEmployees = New ADODB.Recordset
       strSQL = "employee"
       rstEmployees.Open strSQL, strCnxn, adUseClient, adLockReadOnly, adCmdTable
       
       ' Enumerate Recordset
       Do While Not rstEmployees.EOF
          ' Display current record information
          strMessage = "Employee: " & rstEmployees!lname & vbCr & _
             "(record " & rstEmployees.AbsolutePosition & _
             " of " & rstEmployees.RecordCount & ")"
          If MsgBox(strMessage, vbOKCancel) = vbCancel Then Exit Do
          rstEmployees.MoveNext
       Loop    ' clean up
       rstEmployees.Close
       Cnxn.Close
       Set rstEmployees = Nothing
       Set Cnxn = NothingEnd Sub
    'EndAbsolutePositionVB
      

  3.   

    用data1.Recordset.AbsolutePosition 实现