Filling a table with data

S

SC

Hi,

I'm fairly new to Access and I'm trying to fill a table
with random data using code. I can't seem to find
anything on this, all the books talk about is how to
store info based on user input (on a form).

I'd like a small procedure example if possible that,
within a for loop, creates a new record in a table and
then puts data in each field.

Thanks a million,

SC
 
J

Joel Wiseheart

The example code below will add strA and intB to FieldA
and FieldB respectively, in tblTableName. You can use
this as a starting example, and populate the variables
and loop to set the variable values as necessary:


Dim db as DAO.database
Dim rst as DAO.Recordset
Dim strA as String
Dim intB as Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("tblTableName")

strA = "string value"
intB = 1

With rst
.AddNew
!FieldA = strA
!FieldB = intB
.Update
End With

HTH,
Joel
 

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