update entry with code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

want to update a date in a entry in a table called ApmUpdateDate(which only
has one field and one entry - LastUpdateDate)

would like to update it with todays current date when i click on a button
and run the code.need help please

this is my code....


Dim Olddate As DAO.Recordset
Set Olddate = dbs.OpenRecordset("ApmUpdateDate")
Dim datenow As Date
datenow = Now()

With Olddate
.Edit
LastUpdatedate = datenow
End With
 
Since LastUpdateDate is a field in your recordset, you're missing the bang
in front of its name so that Access knows that it's related to the
recordset. You're also missing the Update method to let Access know you're
finished with the Edit:

With Olddate
.Edit
!LastUpdatedate = datenow
.Update
End With

Just as a caution, though. I know your table only has a single row in it, so
what I'm about to say isn't really applicable, but it's seldom (if ever)
appropriate to loop through a recordset setting a particular field to a
single value. Given a choice between using a recordset and using a SQL
Update statement, the Update statement is almost always going to be more
efficient (I actually believe it's always going to be better, but I thought
I'd leave myself some wiggle room! <g>)

I'd replace all of that code with:

CurrentDb.Execute "UPDATE ApmUpdateDate " & _
"SET LastUpdateDate = " & _
Format(Now, "\#mm\/dd\/yyyy hh\:nn\:ss\#"), _
dbFailOnExecute
 
updates the date for me.works a treat.tks


Douglas J. Steele said:
Since LastUpdateDate is a field in your recordset, you're missing the bang
in front of its name so that Access knows that it's related to the
recordset. You're also missing the Update method to let Access know you're
finished with the Edit:

With Olddate
.Edit
!LastUpdatedate = datenow
.Update
End With

Just as a caution, though. I know your table only has a single row in it, so
what I'm about to say isn't really applicable, but it's seldom (if ever)
appropriate to loop through a recordset setting a particular field to a
single value. Given a choice between using a recordset and using a SQL
Update statement, the Update statement is almost always going to be more
efficient (I actually believe it's always going to be better, but I thought
I'd leave myself some wiggle room! <g>)

I'd replace all of that code with:

CurrentDb.Execute "UPDATE ApmUpdateDate " & _
"SET LastUpdateDate = " & _
Format(Now, "\#mm\/dd\/yyyy hh\:nn\:ss\#"), _
dbFailOnExecute
 

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

Back
Top