Re: Updating a recordset

From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 08/14/04


Date: Sat, 14 Aug 2004 00:05:19 -0400


"Allie" <anonymous@discussions.microsoft.com> wrote in message
news:5da801c48156$d2bed9b0$a601280a@phx.gbl...
> I have data going to a second table (tableB) when a
> particular criteria is met. I can add data using the
> recordset Addnew method, I can delete data but I can not
> update the data using the Edit method.
>
> I am using Acc97 and DAO 3.51.
>
> Here is the code I am using:
>
> Dim db As Database
> Dim rs As Recordset
> Set db = CurrentDb
> Set rs = db.OpenRecordset("tableB", dbOpenDynaset)
> With rs
> Edit
> .Fields("BkID") = Me.ID
> .Fields("User") = Me.User
> .Fields("StateNo") = Me.StateNo
> .Fields("Amount") = Me.Amount
> .Fields("DateEntered") = Me.Date
> .Fields("EnteredBy") = CurrentUser()
> .Update
> .Close
> End With
>
> I've tried using the MoveNext and Find and seek methods
> with no luck.
>
> Please help
>
> Thanks

First, if that's a direct quote from your code, it can't work because you
don't have the dot (.) in front of your call to the Edit method. Instead of

> Edit

you'd need to have

  .Edit

Second, what record are you editing here? If the table is empty, you can't
.Edit, you have no choice but to .AddNew. If the table is not empty, this
(corrected) code is always going to update the first record returned in the
recordset. Is that what you want?

-- 
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup, not by e-mail)


Relevant Pages

  • Re: Form View using snapshot?
    ... Allen Browne - Microsoft MVP. ... controls instead of trying to modify the type of recordset the form uses. ... The add and edit work fine. ...
    (microsoft.public.access.formscoding)
  • Re: Edit Method in VB
    ... > I used to edit records in a module by using a tbl.Edit method. ... > under Tools, References, but it still doesn't work. ... but it won't work in my database. ... > method that can be used to edit a record in a recordset? ...
    (microsoft.public.access.modulesdaovba)
  • Re: Form View using snapshot?
    ... Just run the locking code in the Load event of the form. ... controls instead of trying to modify the type of recordset the form uses. ... > The add and edit work fine. ...
    (microsoft.public.access.formscoding)
  • Re: Edit Method in VB
    ... database, I got an error message of "Data type mismatch" on my variable "tbl" ... >> created a new database in Access XP and tried to use the Edit method, ... >> method that can be used to edit a record in a recordset? ... > Dim tbl As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • DAO Add/Edit/Update Methods
    ... Is there something about the Add, Edit and/or Update methods using DAO ... I have known the EditMode property to not be showing in the ... recordset for the record that is suppose to be in EditInProcess mode). ... In the past, it was needed to use dynamic cursor keyset, thus given the DAO ...
    (microsoft.public.access.modulesdaovba)