Re: Update Fails (Access db)
So, what is the Select command and, more top the point, where is it? There are a lot of items here where you seem to take it on trust that that values will carry over from other subs. I'd be very surprised if you could get away with not creating a new Adapter at the very least.
Re: Update Fails (Access db)
Thanks for the quick reply.
The select statement is:
strSelect = "SELECT * FROM tblFinishes"
daFinishes = New OleDb.OleDbDataAdapter(strSelect, con)
daFinishes.Fill(dsFinishes, "tblFinishes")
MaxRowsFinishes = dsFinishes.Tables("tblFinishes").Rows.Count
Originally it was in a module but I moved it to the FormLoad event. This app currently has only one form.
I have also used: "SELECT id, finish FROM tblFinishes" with the same error resulting. 'ID' is the primary key in the Access db. MaxRowsFinishes is used in the app. It always has the correct number of rows.
Re: Update Fails (Access db)
Well there you go then. You can't 'carry over' objects initialised in Form_Load to another sub. You need to initialise an adapter within the AddElement sub.
Re: Update Fails (Access db)
You might like to follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data. It provides code examples that, amongst other things, demonstrate how to manage data access objects that you only need to use in one place and those that you need to use in multiple places. Like any objects, if you need to use them in more than one method then they must be assigned to a variable declared outside all those methods. Exactly where that is depends on the situation but, in your case, it sounds like a simple field, i.e. member variable, in the form is appropriate.