View Full Version : Add new number field


Catalina
10-14-2009, 07:51 AM
A table with 50,000 records needs a new number field (not autonumber).
Then using this field the records have to be numbered 1 - 50,000.
How can I (semi) automate this process?

All suggestions will be appreciated.

Catalina

gemma-the-husky
10-14-2009, 07:58 AM
iterate a recordset in code

Catalina
10-14-2009, 03:17 PM
I was afraid you would say that.

I looked a a lot of samples and couldn't make any of them work for me.
Can you help me along a little please?

Thanks.

Catalina

gemma-the-husky
10-14-2009, 05:23 PM
put this in a module, change the red bits to suit, and run it

5 secs to do 50k entries at a guess

sub process

dim dbs as database
dim rst as recordset
dim val as long


set dbs=currentdb
set rst = dbs.openrecordset("mytable")

val=0

while not rst.eof
val=val+1
rst.edit
rst!counterfield = val
rst.update
rst.movenext
wend

rst.close
set rst = nothing
set dbs= nothing

end sub

Catalina
10-14-2009, 06:04 PM
Thanks, I appreciate it.

How do you run a module though?

Catalina

gemma-the-husky
10-14-2009, 10:37 PM
put the code in a module

place the cursor at the start of the sub

press debug/run

-------
has to be in a code mofule - you cant run code in a form module, directly in this manner

you could easily call it from a button click though

Catalina
10-15-2009, 09:16 AM
And that did the job!.

Thanks for the assistance, I greatly appreciate it.

Catalina