AddNew method doesn't work right!!

AddNew method doesn't work right!!

Post by Amiri Jone » Wed, 26 Aug 1998 04:00:00



    Okay, here's the problem.  I have a database that I'm am manipulating
through VB5 (MDB created in Access 97).  I have several data controls on the
form; one is for the main record, and the others are used for DBCombo boxes.
    I have a New command button which fires the <Data
control>.Recordset.AddNew method.  This works fine.  I also have a Save
button, which fires a <Data control>.Recordset.Update method (the various
text boxes on the form are bound to the main data control).  It saves the
record, just as it's supposed to.
    However, it's HOW the record is saved that is killing me!!  For some
Quote:>BIZARRE< reason, this dumb thing is overwriting existing records!  To

explain, the database is being designed to track PC hardware configurations.
The primary key in the PC table is a PC number field.  Right now, there are
10 records in the table, numbered 1 through 10, sequentially (no, I'm not
using an AutoNumber field).  When I click the New button to generate PC 11,
and then save the record, I can go back to Access and see that the PCs have
been renumbered to run 2 through 11, inclusive!  Furthermore, there are no
new records; there are still only 10 records in the table!
    The data control opens the table as a dynaset, if that's relevant.  I
can add records in Access just fine, and they all stay there.  Can somebody

This is happening on both a stock VB5 Enterprise and an SP3 machine, so
don't suggest SP installation.  Is it something in my code?
 
 
 

AddNew method doesn't work right!!

Post by Alejandro Lapeyr » Wed, 26 Aug 1998 04:00:00


Dear Amiri Jones,

It looks like the program always rewrites the first record.
Please post the code you are using to add the new record.

Alejandro Lapeyre.

Amiri Jones escribi en mensaje ...

>    Okay, here's the problem.  I have a database that I'm am manipulating
>through VB5 (MDB created in Access 97).  I have several data controls on
the
>form; one is for the main record, and the others are used for DBCombo
boxes.
>    I have a New command button which fires the <Data
>control>.Recordset.AddNew method.  This works fine.  I also have a Save
>button, which fires a <Data control>.Recordset.Update method (the various
>text boxes on the form are bound to the main data control).  It saves the
>record, just as it's supposed to.
>    However, it's HOW the record is saved that is killing me!!  For some
>>BIZARRE< reason, this dumb thing is overwriting existing records!  To
>explain, the database is being designed to track PC hardware
configurations.
>The primary key in the PC table is a PC number field.  Right now, there are
>10 records in the table, numbered 1 through 10, sequentially (no, I'm not
>using an AutoNumber field).  When I click the New button to generate PC 11,
>and then save the record, I can go back to Access and see that the PCs have
>been renumbered to run 2 through 11, inclusive!  Furthermore, there are no
>new records; there are still only 10 records in the table!
>    The data control opens the table as a dynaset, if that's relevant.  I
>can add records in Access just fine, and they all stay there.  Can somebody

>This is happening on both a stock VB5 Enterprise and an SP3 machine, so
>don't suggest SP installation.  Is it something in my code?


 
 
 

AddNew method doesn't work right!!

Post by Stan Lak » Wed, 26 Aug 1998 04:00:00


A code sample would be nice.  I suspect that after you ADDNEW, that you
aren't moving to the new record and instead are overwriting the first
record.


>    Okay, here's the problem.  I have a database that I'm am manipulating
>through VB5 (MDB created in Access 97).  I have several data controls on
the
>form; one is for the main record, and the others are used for DBCombo
boxes.
>    I have a New command button which fires the <Data
>control>.Recordset.AddNew method.  This works fine.  I also have a Save
>button, which fires a <Data control>.Recordset.Update method (the various
>text boxes on the form are bound to the main data control).  It saves the
>record, just as it's supposed to.
>    However, it's HOW the record is saved that is killing me!!  For some
>>BIZARRE< reason, this dumb thing is overwriting existing records!  To
>explain, the database is being designed to track PC hardware
configurations.
>The primary key in the PC table is a PC number field.  Right now, there are
>10 records in the table, numbered 1 through 10, sequentially (no, I'm not
>using an AutoNumber field).  When I click the New button to generate PC 11,
>and then save the record, I can go back to Access and see that the PCs have
>been renumbered to run 2 through 11, inclusive!  Furthermore, there are no
>new records; there are still only 10 records in the table!
>    The data control opens the table as a dynaset, if that's relevant.  I
>can add records in Access just fine, and they all stay there.  Can somebody

>This is happening on both a stock VB5 Enterprise and an SP3 machine, so
>don't suggest SP installation.  Is it something in my code?

 
 
 

AddNew method doesn't work right!!

Post by Amiri Jone » Thu, 27 Aug 1998 04:00:00


    Cancel that cry for help; I figured out for myself what was going
wrong...  With some judicious variable watching and breakpoints (God,
debugging in VB is so much easier than in Fortran!), I discovered my
problem.  I had a branch point where the .EditMode property of the recordset
was being evaluated, and if the value was not equal to dbEditNew, then the
.Edit method fired, otherwise nothing happened, since the only time that
segment of code could execute was after either an .AddNew or .Edit method on
the recordset (it was being done this way to implement a log of changes to
the database).
     After reading the help file section on the .EditMode property, I
discovered that VB5 doesn't USE the vbEditNew value for .EditMode property
after executing the .AddNew method.  Instead, it uses the vbEditNew value (I
was using the vbEditNew value after finding it in the Object Browser).
Since EditMode never equaled dbEditNew, the Edit method was always being
invoked, nullifying the AddNew method that had been invoked previously.
Once I switched to comparing the current edit mode to dbEditAdd, everything
worked out properly.
    As an aside, why are there dbEditNew, dbEditChanged, or dbEditDeleted
constants, when the help file clearly specifies that the only possible
values for the EditMode property are dbEditNone, dbEditinProgress, and
dbEditAdd?


>    Okay, here's the problem.  I have a database that I'm am manipulating
>through VB5 (MDB created in Access 97).  I have several data controls on
the
>form; one is for the main record, and the others are used for DBCombo
boxes.
>    I have a New command button which fires the <Data
>control>.Recordset.AddNew method.  This works fine.  I also have a Save
>button, which fires a <Data control>.Recordset.Update method (the various
>text boxes on the form are bound to the main data control).  It saves the
>record, just as it's supposed to.
>    However, it's HOW the record is saved that is killing me!!  For some
>>BIZARRE< reason, this dumb thing is overwriting existing records!  To
>explain, the database is being designed to track PC hardware
configurations.
>The primary key in the PC table is a PC number field.  Right now, there are
>10 records in the table, numbered 1 through 10, sequentially (no, I'm not
>using an AutoNumber field).  When I click the New button to generate PC 11,
>and then save the record, I can go back to Access and see that the PCs have
>been renumbered to run 2 through 11, inclusive!  Furthermore, there are no
>new records; there are still only 10 records in the table!
>    The data control opens the table as a dynaset, if that's relevant.  I
>can add records in Access just fine, and they all stay there.  Can somebody

>This is happening on both a stock VB5 Enterprise and an SP3 machine, so
>don't suggest SP installation.  Is it something in my code?

 
 
 

AddNew method doesn't work right!!

Post by John Robinso » Sun, 30 Aug 1998 04:00:00



>    However, it's HOW the record is saved that is killing me!!  For some
>>BIZARRE< reason, this dumb thing is overwriting existing records!  To

Not to insult your intelligence, but you ARE using Recordset.AddNew instead
of  Recordset.Edit in the code for adding records, right?
 
 
 

1. Doesn't support AddNew Method

I used the following query in VB using SQL -Server 7.0 as the back end:

dim rs as new adodb.recordset

sql = " Select  *  from test where h1=101001 and rt='cfsr' order by
dt_start_date "
provider  =  "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=test;Data Source=Machine1"
rs.open   sql  ,  provider  ,  adOpenDynamic , adLockOptimistic
msgbox  rs.supports(addnew)
rs.addnew

Message box diaplayed FALSE .

The error I got was :
            The operation requested by the application is not supported by
the provider .

            But when I removed Order By clause from the sql query string it
was supporting  Addnew method . May I know what is the problem ?

2. Alter table changes not appearing...

3. Amir's data granularity method doesn't work

4. 1999 problem?

5. TQuery's locate method doesn't work properly

6. a lot invalid objects in sys schema

7. Addnew works but doesn't...

8. Advanced security

9. AddNew with ADO Recordset doesn't seem to work

10. AddNew works, but then it doesn't (ADO)

11. Select right after Insert doesn't work

12. One APPE FROM statement suddenly doesn't work right

13. Scheduled DTS job doesn't work right...help