We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 62,022 times

Contents

Related Categories

DAO 3.6 Library - Editing Records

LouisRose

Editing Records

Now all that's left to provide full functionality in our small library is the ability to change a field's value. To do this we'll use a Function called ChangeField. It'll accept four parameters. The recordset of the record that you wish to update, the id of the record, the name of the field that you wish to change and the value that you wish to change it to.

Like the DeleteRecord function, the ChangeField function returns the ID that you passed to it, if it's successful and -1 if it's not.

Here's the code:

Public Function ChangeField(rstTable As Recordset, intID As Integer, strFieldName As String, varValue As Variant)As Integer
   With rstTable
      .Requery
      .FindFirst "ID = " & intID
      If .NoMatch = True Then
         ChangeField = -1
      Else
         .Edit
         .Fields(strFieldName).Value = varValue
         .Update
         ChangeField = intID
      End If
   End With
End Function


The code requeries the table as usually, moves to the record that we want to change and uses the .Fields structure to alter the field that you specified to include the value that you passed to it. The special .Update method ensures that the changes are recorded by Access. To use this function use the following code.. (This is assuming that we want to change field FirstName of record 4 of recordset rstPeople to "Louis"):

Dim intReturn as Integer
intReturn = ChangeField(rstPeople, 4, "FirstName", "Louis")

Comments

  • Re: [2527] DAO 3.6 Library

    Posted by BarbStewart on 12 Jun 2008

    I am working in VB6 with an Access db and would like to delete records from a join table. Can you help me? I have a table of Products, and table of Materials and a table to join the...

  • Re: [2527] DAO 3.6 Library

    Posted by faisalwadood on 20 Feb 2007

    hi sir!


    i hav read your article fully,i also read many articles on vb databases i understand it well yet i hav have a problem if you kindly help me.


    i want to develop a vb applicati...

  • Re: [2527] DAO 3.6 Library

    Posted by Nishantha on 13 Jul 2006


    Dear Sir,


    <...

  • Bad Type

    Posted by StevoMc on 14 Jul 2004

    This tutorial has been really good for helping me understand how to use access databases, which is really cool, but unfortunately I'm having a problem.

    When writing the code for moddefaultdatabase...

  • Posted by bruwmac on 22 Jun 2004

    What? Where the heck did that come from?

    :eek: :confused: :D