Saving a New Record

jcruzAME

Registered User.
Local time
Today, 13:30
Joined
Oct 5, 2011
Messages
135
I'm currently working with a program that used to have an Access back end and is now in SQL. There is a form whose data is pulled from a table.

In the one with an Access backend, whenever you create a new record, it seems to assign itself an ID automatically, no where in the code is there a me.dirty or docmd.save (well, there are but they happen AFTER it seems to assign an ID). It seems to assign it after you've entered information in any of the text/combo boxes on the form, but there are no after updates that I can find.

Now, in the version with the SQL back end, where I've basically brought over the old code and debugged it, if I enter information and then do something like a if me.dirty it will still have no ID after I hit that code.

What does it do different when there is an SQL back end? The reason this is a problem is because on some of the combo boxes it runs some code that needs the ID of the current record, but in the SQL back end version it never seems to assign one.

Any insight would be appreciated.
 
I tried doing a Me.Dirty after you enter text into the first text box on one of the forms and I still get a Null ID for that record.

Does SQL just save new records differently?
 
It has nothing to do with saving the Record! The problem is that your 'automatically assigned' ID was, in Access, defined as an Autonumber Field, and the various flavors of SQL back ends handle this differently. If I remember correctly, MySQL, for instance, will not accept the Field as an Autonumber unless it was also, in Access, the Primary Key. If it wasn't desinated as the Primary Key then MySQL simply makes it an Number/Integer which doesn't auto-generate itself, like an Autonumber in Access does.

Other types of 'SQL' back ends may handle it differently, still. What, exactly, do you mean when you say it has a SQL back end?

Linq ;0)>
 
Well I just realized that on one form, if use me.dirty after the first entry, it will save it in the table and give it an ID number.

The other form, which has VERY similar code and does nearly the same thing, doesn't.

In regards to your question, we use linked tables that link to an SQL database. I use SQL Server Management Studio if I need to modify the designs of the tables. We also have a few stored procedures. I also checked and the ID fields in both tables are the Primary Key.
 

Users who are viewing this thread

Back
Top Bottom