Creating and populating a table

  • Thread starter Thread starter Becky
  • Start date Start date
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
 
Yes. Think of filling the data with random Alphas based on random ascii
numbersin each position.

Regards

Kevin
 
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!
 
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]

.
 
Back
Top