AddNew method doesn't work right!! 
Author Message
 AddNew method doesn't work right!!

    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?


Sat, 10 Feb 2001 03:00:00 GMT  
 AddNew method doesn't work right!!
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 ...

Quote:
>    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?



Sat, 10 Feb 2001 03:00:00 GMT  
 AddNew method doesn't work right!!
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.

Quote:

>    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?



Sat, 10 Feb 2001 03:00:00 GMT  
 AddNew method doesn't work right!!
    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?

Quote:

>    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?



Sun, 11 Feb 2001 03:00:00 GMT  
 AddNew method doesn't work right!!

Quote:

>    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?


Wed, 14 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Databound Checkbox doesn't work BindingContext(...).AddNew

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

3. Addnew works but doesn't...

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

5. Addnew Doesn't Addnew!

6. Loop statement doesn't work right

7. right alignment in richtextbox doesn't work

8. Form menu editor doesn't work right??

9. Help: Control Box doesn't work right.

10. Q: Why auto-redraw doesn't work right in Windows-NT

11. Right$ doesn't work!

12. Select method doesn't work properly

 

 
Powered by phpBB® Forum Software