AddNew/Update table

A

Ann

I am trying to have an AfterUpdate event on a text box in
a form that adds a record that you put in the text box to
a table. My code is:

Private Sub Text8_AfterUpdate()
Dim Sample_Date As Date
Dim rs As DAO.recordset

rs.AddNew [Sample_Date]
rs.UpDate [Sample_Date]

End Sub

where Sample_Date is the field to be updated.

Can someone help me with the code and/or suggest a good
VBA refernce book for a beginner? Thank you very much.
 
M

Marshall Barton

Ann said:
I am trying to have an AfterUpdate event on a text box in
a form that adds a record that you put in the text box to
a table. My code is:

Private Sub Text8_AfterUpdate()
Dim Sample_Date As Date
Dim rs As DAO.recordset

rs.AddNew [Sample_Date]
rs.UpDate [Sample_Date]

End Sub

where Sample_Date is the field to be updated.

Can someone help me with the code and/or suggest a good
VBA refernce book for a beginner? Thank you very much.

That should be more like:

Dim db As Database
Dim rs As DAO.recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("table")
rs.AddNew
rs![Sample_Date] = Me.thetextbox???
rs.UpDate
rs.Close
Set rs = Nothing
Set db = Nothing

There's actually a relevant example of this in Help - AddNew

Somehow, I get the feeling that this is not what you really
want to do to meet whatever need this code was attempting to
address.

I'm not familiar with beginner books, but maybe someone else
can make a suggestion.
 
G

Guest

Thanks,

I'll have to try it on Tuesday.
-----Original Message-----
Ann said:
I am trying to have an AfterUpdate event on a text box in
a form that adds a record that you put in the text box to
a table. My code is:

Private Sub Text8_AfterUpdate()
Dim Sample_Date As Date
Dim rs As DAO.recordset

rs.AddNew [Sample_Date]
rs.UpDate [Sample_Date]

End Sub

where Sample_Date is the field to be updated.

Can someone help me with the code and/or suggest a good
VBA refernce book for a beginner? Thank you very much.

That should be more like:

Dim db As Database
Dim rs As DAO.recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("table")
rs.AddNew
rs![Sample_Date] = Me.thetextbox???
rs.UpDate
rs.Close
Set rs = Nothing
Set db = Nothing

There's actually a relevant example of this in Help - AddNew

Somehow, I get the feeling that this is not what you really
want to do to meet whatever need this code was attempting to
address.

I'm not familiar with beginner books, but maybe someone else
can make a suggestion.
 

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

Similar Threads

date data type 1
append SQL no records 8
forms Coding 6
NotInList not firing ? 1
NotInList Warning 4
Error in Input Box 3
Multi Select List Box in Access 0
openrecordset is SLOW 3

Top