Inserting Data into a table

D

Doug

Hi,

I'm trying to insert today's date into a field every time
the code is run. I have the following code, which
currently doesn't do anything when run.

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLastUpdate")
rst.AddNew
rst("lastupdate") = Date ()
rst.Close
dbs.Close

LastUpdate is the name of the field.

Thanks in advance for your help.
Doug
 
J

Jeff Conrad

You're missing just one tiny important detail. You did not include the "Update" statement to tell
Access to actually update the record. Try this:

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLastUpdate")
rst.AddNew
rst("LastUpdate") = Date
rst.Update
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
 
D

Doug

Jeff,

That did it. A bit of an oversight on my part. Thanks
for the help.

Doug
-----Original Message-----
You're missing just one tiny important detail. You did
not include the "Update" statement to tell
 

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