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