addnew and update methods ? 
Author Message
 addnew and update methods ?

Hi,

I'm using VB 4.0 with ODBC driver and SQL Server 6.5.
My data controls are using the following Connect string:
        ODBC;DATABASE=ICIIS;UID=ICIISUser;PWD=iciisuser;DSN=dsVB1;

I'm trying to use a cmdAdd button to add a new record to the CustInfo
table in the DB. Before I update the change, I need to read the max ID
using for the CustInfo table from another data control. I use the
following codes:

Private Sub cmdAdd_Click()
    datMaxID.Recordset.Edit
    datMaxID.Recordset.Fields("CustSuppID").Value = datMaxID.Recordset.Fields("CustSuppID").Value + 1
    datMaxID.Recordset.Update
    datCustInfo.Recordset.AddNew
End Sub

And I use another button cmdSave to save the change.

Private Sub cmdSave_Click()
    txtCustInfoID.Text = datMaxID.Recordset.Fields("CustSuppID").Value
    datCustInfo.Recordset.Update
End Sub

When I tried to run these, there's no prob when the table is empty.
But if there're some rows in the table, it will get run-time error
of 3020 "Update or CancelUpdate without AddNew or Edit."
at the Update method.

Am I missing anything??

Thanks in advance.

--
   ___  _          

 |  _  | / _` | ' \  Future Solutions Laboratory Limited (852)2319-2488
 |_| |_|_\__,_|_||_| Rm 317, HKITC, Tat Chee Avenue, Kowloon, Hong Kong



Tue, 22 Jun 1999 03:00:00 GMT  
 addnew and update methods ?



Quote:
>When I tried to run these, there's no prob when the table is empty.
>But if there're some rows in the table, it will get run-time error
>of 3020 "Update or CancelUpdate without AddNew or Edit."
>at the Update method.

>Am I missing anything??

>Thanks in advance.

I'm kind of a novice here myself, but maybe it's a problem at the time
you create the datCustInfo resultset.  I assume datCustInfo is the
rdc.  What sql does it use?

J.



Fri, 02 Jul 1999 03:00:00 GMT  
 addnew and update methods ?

Hi,

That error occurs when you have not first put an AddNew or Edit.  As an
example:

    Set db = DBEngine.Workspaces(0).OpenDatabase("myDB")
    Set rs = db.OpenRecordset("myTable")

    rs.AddNew '<------------------------------------ this is what is
missing
    rs("ContactName") = "JRStern"
    rs.Update

    ' or for Edit:

    rs.Edit '<------------------------------------------- the other thing
that can be missing
    rs("ContactName") = "JRStern"
    rs.Update

In the first example you are adding a new record, in the second example you
are editing an existing record.

Note: I did not show the code that locates that existing record.  And when
you edit, naturally there has to be a current record.

Hope this helps, good luck ;-)

Jerry Hill



Quote:


> >When I tried to run these, there's no prob when the table is empty.
> >But if there're some rows in the table, it will get run-time error
> >of 3020 "Update or CancelUpdate without AddNew or Edit."
> >at the Update method.

> >Am I missing anything??

> >Thanks in advance.

> I'm kind of a novice here myself, but maybe it's a problem at the time
> you create the datCustInfo resultset.  I assume datCustInfo is the
> rdc.  What sql does it use?

> J.



Fri, 02 Jul 1999 03:00:00 GMT  
 addnew and update methods ?

Don't know if it is related in any way but someone I work with was
getting this error from VB4.0 Professional Edition whenever she tried
to create a record for a recordset and one of the fields displayed on
the screen that was a field in the record to be inserted was a dbcombo
box.  If the field assignment was commented out (allowing the field to
contain a null), the insert worked correctly, uncomment the assignment
and the 3020 error occurred.  The addnew property and the assignments
for the dbcombo box were correct.

Quote:



>>When I tried to run these, there's no prob when the table is empty.
>>But if there're some rows in the table, it will get run-time error
>>of 3020 "Update or CancelUpdate without AddNew or Edit."
>>at the Update method.

>>Am I missing anything??

>>Thanks in advance.
>I'm kind of a novice here myself, but maybe it's a problem at the time
>you create the datCustInfo resultset.  I assume datCustInfo is the
>rdc.  What sql does it use?
>J.

Frank Thomas



Sun, 04 Jul 1999 03:00:00 GMT  
 addnew and update methods ?

Quote:
> Private Sub cmdAdd_Click()
>     datMaxID.Recordset.Edit
>     datMaxID.Recordset.Fields("CustSuppID").Value =

datMaxID.Recordset.Fields("CustSuppID").Value + 1

Quote:
>     datMaxID.Recordset.Update
>     datCustInfo.Recordset.AddNew
> End Sub

> And I use another button cmdSave to save the change.

> Private Sub cmdSave_Click()
>     txtCustInfoID.Text = datMaxID.Recordset.Fields("CustSuppID").Value
>     datCustInfo.Recordset.Update
> End Sub

> When I tried to run these, there's no prob when the table is empty.
> But if there're some rows in the table, it will get run-time error
> of 3020 "Update or CancelUpdate without AddNew or Edit."
> at the Update method.

> Am I missing anything??

What is the SQL statment used to create the datCustInfo recordset?
Are you using any MoveFirst, MoveNext or Seek methods after using the
AddNew?


Tue, 13 Jul 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. AddNew and Update Methods for Dynaset multiple tables

2. Addnew and update method in ADOCE not working ?

3. AddNew and Update ADO methods

4. Update: Problems using AddNew method of Recordset

5. Update method and Requery method

6. Updating Links in Word 2002, Edit, Links, Select Update Method

7. AddNew method

8. Returning PK values of record added by .AddNew method

9. AddNew method

10. AddNew Method overwrites existing records??

11. AddNew Method...

12. Help Please... AddNew Method error

 

 
Powered by phpBB® Forum Software