From: gator on
I have a form with three fields - textbox1, textbox2, textbox3. Each textbox
will have text or a number in it. what code will INSERT textbox1 into new
record in Table1 field1, then INSERT textbox2 into new record Table1 field1,
and so on? Is it a Loop or Array, I'm confused.
From: John W. Vinson on
On Fri, 5 Mar 2010 12:26:17 -0800, gator <gator(a)discussions.microsoft.com>
wrote:

>I have a form with three fields - textbox1, textbox2, textbox3. Each textbox
>will have text or a number in it. what code will INSERT textbox1 into new
>record in Table1 field1, then INSERT textbox2 into new record Table1 field1,
>and so on? Is it a Loop or Array, I'm confused.

What's the context? Does your table have only one field? Is this an unbound
form (which needs code) or a bound form (which should be storing data into a
table directly)?

As you pose the question you would need some VBA code to open a recordset and
write three records to it... but this seems like a really strange way to do
things; even so, here's some sample code that you could adapt. Put it in the
Click event of a button on your form:

Private Sub cmdWriteIt_Click()
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("Table1", dbOpenDynaset)
rs.AddNew
rs!Field1 = Me.Textbox1
rs.Update
rs.AddNew
rs!field1 = Me.Textbox2
rs.Update
rs.AddNew
rs!field1 = Me.Textbox3
rs.Update
rs.Close
Set rs = Nothing
End Sub

The code could be rewritten to use a loop if you prefer.
--

John W. Vinson [MVP]