Creating and populating a table

B

Becky

I would like to ask for some help. As a new programmer, I am testing some of
my subs and fuctions. To help with this, I'd like a table with 2 fields, ID
(autonumber) and strWord (these are 20 RANDOM letters long, a to z. Doubles
are OK). Rows might look like...

ID strWord
1 yhwtqggenmlportoinai
2 mlloapiqwtqmcjustepu ...etc.

Is there a fast way I can generate the table and populate it with, say, 5000
random words?

much thanks
Becky
 
K

kc-mass

Yes. Think of filling the data with random Alphas based on random ascii
numbersin each position.

Regards

Kevin
 
J

John W. Vinson

I would like to ask for some help. As a new programmer, I am testing some of
my subs and fuctions. To help with this, I'd like a table with 2 fields, ID
(autonumber) and strWord (these are 20 RANDOM letters long, a to z. Doubles
are OK). Rows might look like...

ID strWord
1 yhwtqggenmlportoinai
2 mlloapiqwtqmcjustepu ...etc.

Is there a fast way I can generate the table and populate it with, say, 5000
random words?

much thanks
Becky

sounds like fun...

Create the table with the autonumber and text field in table design view; then
run

Public Sub RandomText()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer, j as Integer
Dim strT as String
Randomize
Set db = CurrentDb
Set rs = db.OpenRecordset("YourTableName", dbOpenDynaset)
For i = 1 to 5000
rs.AddNew
strT = ""
For j = 1 to 20
strT = strT & chr(97+fix(26*rnd()))
Next j
rs!textfield = strT
rs.Update
Next i
End Sub

Untested air code, might not get z or might include some { - tweak as needed!
 
B

Becky

Excellent - thank you, John.
Becky

John W. Vinson said:
sounds like fun...

Create the table with the autonumber and text field in table design view; then
run

Public Sub RandomText()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer, j as Integer
Dim strT as String
Randomize
Set db = CurrentDb
Set rs = db.OpenRecordset("YourTableName", dbOpenDynaset)
For i = 1 to 5000
rs.AddNew
strT = ""
For j = 1 to 20
strT = strT & chr(97+fix(26*rnd()))
Next j
rs!textfield = strT
rs.Update
Next i
End Sub

Untested air code, might not get z or might include some { - tweak as needed!
--

John W. Vinson [MVP]

.
 

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

Top