|
-
Jan 11th, 2003, 02:11 PM
#1
Thread Starter
Fanatic Member
Create my own AutoNumber Field with AbsolutePosition
I wanna create my own AutoNumber Field with AbsolutePosition function. So it always is in numeric order and no number been skipped.
I do like this, but it doesen't work:
VB Code:
Dim Db As Database
Dim rs As Recordset
Dim SQL, SQL1 As String
Set Db = CurrentDb
SQL = "SELECT * From Table1"
Set rs = Db.OpenRecordset(SQL)
With rs
.MoveLast
.MoveFirst
Do While Not .EOF
SQL1 = "UPDATE Table1 SET Table1.[IDT]=" & "'" & .AbsolutePosition + 1 & "'"
Db.Execute SQL1
.MoveNext
Loop
.Close
End With
Set Db = Nothing
Set rs = Nothing
I guess I missed that I should have any criteria somewhere, but I dont know how I should do.
-
Jan 11th, 2003, 03:05 PM
#2
You need to add the Where clause. Always try to use the table's primary key (I am assuming its IDT).
VB Code:
SQL1 = "UPDATE Table1 SET Table1.[IDT]=" & "'" & .AbsolutePosition + 1 & "'"
SQL1 = SQL1 & " Where Table1.[IDT] = " & "'" & .Fields("IDT").Value & "'"
-
Jan 11th, 2003, 03:22 PM
#3
Thread Starter
Fanatic Member
Thanks brucevde!
I have found another solution also:
VB Code:
Dim Db As Database
Dim rs As Recordset
Dim SQL As String
Set Db = CurrentDb
SQL = "SELECT * From Table1"
Set rs = Db.OpenRecordset(SQL)
With rs
.MoveLast
.MoveFirst
Do While Not .EOF
.Edit
!IDT = .AbsolutePosition + 1
.Update
.MoveNext
Loop
.Close
End With
Set Db = Nothing
Set rs = Nothing
Last edited by Pirre001; Jan 11th, 2003 at 03:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|