Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing first row table data in VBA

Status
Not open for further replies.

RiderJon

Programmer
Aug 26, 2002
190
FR

Hello,

I have a table with just one field. Using the "on click" button I want to replace the first row with today's date/time. I have the code to add the date to the table. using db1.AddNew (see code below).

But I don't want the table to grow, I just want the first row data to be replaced i.e. replace Feb 05, 2004 with Feb 20, 2004 in the table shown below.



THE TABLE:

LastDate
--------------
Feb 20, 2004



The CODE:

Set db1 = dbs.OpenRecordset("tbl1")
db1.____________
db1![LastUpdated] = Now()
db1.Update
db1.Close



Thank you,

RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
db1.MoveFirst

if you are using Access 97 or are working with a DAO recordset you will also need a:

db1.Edit

right after the db1.MoveFirst line

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
RiderJon,
I was fishing around in here looking to learn something before quitting time. If your table only has one row (I assume that's the case because you talk about the "first" row, and there is no order by that would establish which one was "first").

Here's a quick and dirty way to update that one field (it won't work if you have multiple rows because it will update all of them).

Private Sub testsub()
CurrentProject.Connection.Execute "update tbl1 set LastDate = #" & Now() & "#"
End Sub

The advantage is there is no recordset to hose with :).

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top