Randomly populating data fields

  • Thread starter Thread starter Florida Ad Guy
  • Start date Start date
F

Florida Ad Guy

I have a table with about 20,000 records in it. I have an empty field in the
table that i want to randomly populate with numbers between 1 - 100. I think
I need to use an Update query for this, but I have no idea what expression
should be used.

I'm pretty strong with the wizards and calculated expressions, but I've
never written actual code. Does anyone know how to do this from an Update
query?

Please help!!
 
I have a table with about 20,000 records in it. I have an empty field in the
table that i want to randomly populate with numbers between 1 - 100. I think
I need to use an Update query for this, but I have no idea what expression
should be used.

I'm pretty strong with the wizards and calculated expressions, but I've
never written actual code. Does anyone know how to do this from an Update
query?

Please help!!

An update query will update every row to the same random number. I
would do a simple VBA loop:

Sub MakeRandomNumbers()

Dim rs as recordset
set rs = currentdb.openrecordset("MyTableName")

do until rs.eof
rs.edit
rs("TheField") = Int(Rnd()*100)
rs.update
rs.movenext
loop

rs.close

End Sub

This will iterate through the table and drop a number from 1-100 in
your field. Just update the table name and field name.

Hope this helps,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top