
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?