我想用个字段作为记录的标识数,它的顺序任何时候都应该是1,2,3,4,5,6,7,8,9,10,11,12,13....,但是当我把其中的一条或几条记录删除,如果把3,4,10这三条记录删除,它的顺序就变成了1,2,5,6,7,8,9,11,12,13,而不是我想要的1,2,3,4,5,6,7,8,9,10,这样如果我想定位的某条记录根本就不准确,有什么好的方法可以达到我的目的吗?具体要怎样写代码?

解决方案 »

  1.   

    先按该字段排序查出记录集,把字段的1,2,5,6,7,8,9,11,12,13这个字 段的值重新赋一次值,赋成1,2,3,4,5,6,7,8,9,10。首先这个字段应该设置成long型数字:
       dim N as long
       Dim strSQL As String
       
       dim conn as New ADODB.Connection
       dim rs as New ADODB.Recordset
       
       strSQL = App.Path & "\A.mdb"
       strSQL = Replace(strSQL, "\\", "\")
       
       With conn
           If .State = adStateOpen Then
              .Close
           End If
           .CursorLocation = adUseClient
           .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & strSQL
           .Open
       End With
         
       With rs
           .Open "Select * from Table1 ORDER BY id;", conn, adOpenStatic, adLockOptimistic
           If .BOF And .EOF Then
              msgbox "没有任何记录"
              Exit Sub
           End If
           .MoveFirst
           .movelast
           msgbox "有" & .recordcount & "条记录!"
           N = .recordcount
       End With
       dim i as long
       if N=0 then exit sub
       rs.movefirst
       for i =1 to N
          with rs
              .id = i
              .update
              .movenext
          end with
       next i
      

  2.   


       dim i as long
       if N=0 then exit sub
       rs.movefirst
       for i =1 to N
          with rs
              .id = i
              .update
              .movenext
          end with
       next i
    上面这段代码中,rs有id属性吗?应该没有吧