Solved

ODBC Calls Faile

Posted on 2013-12-20
11
468 Views
Last Modified: 2013-12-21
I am sure this is an obvious one, but for some reason everything I try is not working.

I have an Access front-end with a SQL back-end connected via ODBC.

I have a form with multiple sub-forms.

When I add a new parent record one of the related tables throws:

ODBC--call failed. Cannot insert the value NULL into column 'link to parent'  column does not allow nulls. Insert fails. (#515) The statement has been terminated. (#3621)

The parent table has a RecordID (PK, int, not null) as a key. The related table (bound to the subform) has a RecordIDLink (PK, FK, int, not null)

I had what I thought were correct database diagrams where I set it for Cascading events, etc.

When this error started popping up I deleted the diagrams and reconnected to the linked tables. I even tried to use an append query to add the related record as soon as I go to a new record and that is still throwing the error.

Please help!!!

Thanks Experts.
0
Comment
Question by:Ei0914
  • 5
  • 5
11 Comments
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Check main form alone.
Then add one sub form at a time and try.

If you can send sql to create the tables, then upload the access database sample.
0
 

Author Comment

by:Ei0914
Comment Utility
Hi thank you for responding. I actually know which sub-form is the culprit and which table is causing this.  I link the subform to the main form with the field in question which means it should automatically be populating that field based on the value on the parent form. It almost seems that despite the fact that when I add a new record and force a save so the autonumber is generated that the related table represented by this particular subform is being updated before the autonumber exists. Does that seem possible??
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Autonumber is used in main table, other related tables should use a number field, not Autonumber to link with parent tables field..
0
 

Author Comment

by:Ei0914
Comment Utility
That's exactly right. The related table has a numeric field linked to the parent autonum.
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Fine.
Compare between the problem table and other working one.

If you can, try to help me in reproducing the issue.
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:Ei0914
Comment Utility
There are 6 subforms on the main form -- all related by a numeric field linked to the parent autonum field.

When I click Add new on the parent form I go to a new record, force a save to generate the autonum (which is displayed on the form so I can watch when it gets generated) and before it displays I get the OBDC error -- which tells me that somehow the subform is adding the record before the parent record is saved.

That is the issue. Not sure what else you need in order to assist me. I can't backup the SQL tables because the data is proprietary and stored on my client's server.
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Since you know the issue, I expect you to recreate it using dummy tables reflecting the structure of the original tables populated with dummy info.

Doing that might lead you to the solution.
0
 

Author Comment

by:Ei0914
Comment Utility
I see. If I were to do that using Access tables I will not get the ODBC errors. Maybe someone else has had this problem in the past who can help me. Thanks a lot.
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
"I see. If I were to do that using Access tables I will not get the ODBC errors"
I mean to do that using the same environment.

"Thanks a lot."
Welcome!
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
force a save to generate the autonum (which is displayed on the form so I can watch when it gets generated)
Is tihs just for testing, or is this something that is done in the live version of the app?

Are you running code in the Subform at any point? The error you're getting indicates that a record is Dirty in that subform, and Access is trying to save it.

Are you absolutely sure that you've properly set the Master and Child links for that subform? Check those, then check them again.

I've had troubles similar to this with linked SQL tables, and in those cases I've had to delete the linked table, and then add it back. I had to make sure the SQL table had a PK defined on it, and that the PK was carried over to the Access link. You can view the Indexes of a linked table by opening that linked table in design view, and reviewing the Indexes.
0
 

Author Closing Comment

by:Ei0914
Comment Utility
I'm an idiot! On the subform I recently did make a change to force a save because that subform has a subform on it as well.... Geez.... no wonder it just started happening. I had completely forgotten about that.

Thanks LSM!!!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now