Filling a table with data

  • Thread starter Thread starter SC
  • Start date Start date
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
 
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
 
Back
Top