Advertisement

09.11.2007 at 04:05AM PDT, ID: 22819960
[x]
Attachment Details

ADO .ADDNEW - Do you need .insert or .update?

Asked by dleads in Microsoft ADP

Tags: addnew, ado, insert, update

A few days ago I asked the following question and received this reply from a former programmer of the system I've taken over "Unless you plan to replace all the code with the Insert into procedure, Please reverse what you did on the tables. Or none of the existing code that uses these tables will work."

Is that true?  If you use an .addnew, do you need to do an insert or can you simply do an update?

This is the former question prompting my new question above:
I'm using Access 2007 adp to SQL 2005 - I am converting mdb to adp.
I've taken over this project and I'm not sure if this was done wrong or if I've missed something.

If my SQL table has ID PK incrementing identity fields, is there any reason to manually increment the ID column when you insert a new record in ado in Access?  Doesn't SQL do that automatically?

Here's one example of the existing code...
Dim rs As New ADODB.Recordset
'GET LAST id NUMBER
sql = "select TOP 1 * FROM matters ORDER BY ID DESC"
rs.Open (sql), CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
Nid = rs![ID] + 1
rs.Close
Set rs = Nothing

rs.Open "select * from matters", CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic

rs.AddNew
rs![ID] = Nid
rs![DATE] = Now
 rs![CLIENT NUMBER] = Me.Parent![CLIENT NUMBER]
 rs![SubNumber] = Me.Parent![SubNumber]
rs.Update

 Angellll responded...
>If my SQL table has ID PK incrementing identity fields, is there any reason to manually increment the ID column when you insert a new record in ado in Access?  Doesn't SQL do that automatically?

yes, sql does that automatically, so you simply don't need to code for that field at all.Start Free Trial
[+][-]09.11.2007 at 04:30AM PDT, ID: 19867574

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft ADP
Tags: addnew, ado, insert, update
Sign Up Now!
Solution Provided By: LSMConsulting
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.11.2007 at 05:31AM PDT, ID: 19867936

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628