Writing Text boxes to records

J

James Mckillop

I am fairly new to VB and am trying to use a button to write the contents of
two unbound text boxes to a table.

The steps I think it needs to follow are
Open table
write Contents of textbox1 to table.field
write contents of textbox2 to table field2
close table.

I don't know any of the syntax for this and can not find the right on under
the DoCmd section.

Help please.
 
J

John Vinson

I am fairly new to VB and am trying to use a button to write the contents of
two unbound text boxes to a table.

VB? or Access VBA? They're not the same.
The steps I think it needs to follow are
Open table
write Contents of textbox1 to table.field
write contents of textbox2 to table field2
close table.

I don't know any of the syntax for this and can not find the right on under
the DoCmd section.

You'll need to open a Recordset based on the table, use the AddNew
method, and write the data. This is VBA code, assuming that the code
is in an event on an Access Form.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("table", dbOpenDynaset)
rs.AddNew
Rs!field = Me!textbox1
Rs!Field2 = Me!textbox2
rs.Update
rs.Close
Set rs = Nothing

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

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