Write to table.

T

Tom

Sorry for this qustion but I am access-vb beginner.

I have form with subform. I need by vb code read/write data directly to a
table. I know column name and I have uniqe row number.
How can I do it.

thanks for your help!
Tomas

P.S. if you know good web page for access-vb dummies, let me know.
 
D

Damiaan

The code:

For a New records:

Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM City WHERE City_ID=0", CurrentProject.Connection,
adOpenForwardOnly, adLockOptimistic
rs.AddNew
rs("City_ModifyDate") = Now
rs("City_ModifyUser_ID") = m_User.Id
rs.Update
rs.Close

==> For an existing records change the 0 => WHERE City_ID=" &
me.txtFieldOnForm
and do not use AddNew but Edit
Note: You can also use e.g. rs!City_ModifyDate instead of the notation above

Or you can use direct SQL in your code:

Dim cnn As New ADODB.Connection
Set cnn = CurrentProject.Connection
cnn.Execute "UPDATE " & tableName & " SET active=true , createDate=now(),
Createuser_ID=1 WHERE ID=" & TheIdYouWant

--

Kind Regards
Damiaan
e: info at dampee.be
w: http://www.dampee.be
 
J

John Vinson

Sorry for this qustion but I am access-vb beginner.

I have form with subform. I need by vb code read/write data directly to a
table. I know column name and I have uniqe row number.
How can I do it.

Several ways - but using a bound form is generally much the simplest
approach.

Could you explain a bit more? What are the Recordsources of the form
and the subform? What data do you want written, into what table? One
record per episode, or will you be writing multiple records at once?

John W. Vinson[MVP]
 

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