Writing data to a table

T

Todd

I'm a new user and I'm hoping this is a very simple
question:

I need to know what the code commands are to write data to
a table from a function.

Basically, I have a while loop that performs a calculation
until a counter is reached. Each time the loop advances,
I want to write the calculation result to a field in a
table, each time through the loop, it should advance to
the next record,and populate the next corresponding record.

What is the code for this?

Note: I realize that there may be simpler ways to do this
with queries and such, however, I need these simple
building blocks of code to do some more complicated stuff
that I don't want to do with queries.

Thanks.
 
A

Allen Browne

You're right: queries may be easier, but here is the code to loop through
all records in a table and modify a field:

Dim rs As DAO.Recordset
Set rs = dbEngine(0)(0).OpenRecordset("MyTable", dbOpenDynaset)
With rs
Do While Not .EOF
.Edit
!SomeField = SomeValue
.Update
.MoveNext
Loop
End With
rs.Close
Set rs = Nothing

Note: if the first line generates an error, you need a reference to the DAO
library. More info:
http://allenbrowne.com/ser-38.html
 

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