Results 1 to 4 of 4

Thread: AddNew Overwrites

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Antrim
    Posts
    80

    Question

    Hi,

    I'm using a DAO data control to connect from VB5 to Access 97 using a dynaset type recordset.

    On using the AddNew method the new record is being added over the top of the current record.

    This results in the old record being lost when the new record is saved and therefore, no matter how many entries I add, I have only one record in my database.

    What am I doing wrong?

    Any help would be much appreciated.

    Best Regards,

    Rob Brown.

  2. #2
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    Hi Rob,
    It sounds as though you've got a statement somewhere that's moving you to the previous record or something.
    When you have .AddNew a NEW record is prepared ready for entries, and .Update stores them.
    It's always a good idea to post your code with the question...its easier to answer then. Post it and someone will help you (probably not me 'cos its 2.15 a.m and I'm ready for some kip).

    Cheers
    GRAHAM

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Antrim
    Posts
    80

    Here's the code...

    Here is my code:

    Private Sub mnuReportAddNew_Click()

    dtaReport.Recordset.AddNew

    End Sub

    As you can see it's not very complicated.

    According to the help file, with the dynaset type recordset this should add a new record at the end of the recordset amd allow them to edit the new record.

    I am then using a save changes menu item to update the database, it uses the following code:

    dtaReport.Recordset.Edit
    dtaReport.Recordset.Update

    Thanks for taking the time to help me out.

  4. #4
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    Hi Rob,
    Take a look at the code in this Function...It illustrates the .AddNew.

    Assuming that sName & sPhone are the entered values that were input from textboxes or whatever/whereever

    Function AddToDatabase(sName As String, sPhone As String)

    '***look at this section******
    'Open the Contact table
    Set RS = DB.OpenRecordset("SELECT * FROM Contact", dbOpenDynaset)
    With RS
    'Set it to Add mode
    .AddNew
    'Enter the field values
    .Fields("Name").Value = sName
    .Fields("Phone").Value = sPhone
    'Update it i.e save
    .Update
    'Close it
    .Close
    End With
    ************************
    End Function

    The above is very basic, but should point you in the right direction.
    I hope this helps you solve your problem; sorry I can't help you any further, but I've got to finish my front-end project(like yesterday)

    Cheers
    GRAHAM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width