Solved

Make blank cell in Delphi "You cannot add or change a record because a related record is required..."

Posted on 2011-09-10
3
275 Views
Last Modified: 2012-05-12
I'm using Delphi with an MS Access Database.

I have two tables

Kid Names
==========
John
Mary
Paul

Class List
===========
Grade | Name
-------  ---------
Grade 2 | John
Grade 7 |
Grade 3 | Mary

Now for some reason, in Delphi, once a cell is modified, it will not let me change it to a BLANK cell again.

Yes these two tables are in a relationship.

But Delphi is OK with the cell being a blank cell--BEFORE a change is propagated. But once you propagate a change, and try to go blank again, you get the error message in the Title of this thread.

This is obviously because, there is no blank cells in table KIDS NAMES.

So how do i find a way to specify that I do not wish to assign a kid to GRADE 7 at this time. e.g. i want to leave it blank for now...?
0
Comment
Question by:bobbysdog
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 36517459
you don't want blank (empty string) but NULL value
something like this

procedure SetClassKid(KidName:String);
Var
 fldName:TField;
begin
 fldName:=tblClassList.FieldByName('NAME');
 if KidName<>''
  Then fldName.Value:=KidName
  Else fldName.Clear;  // set this field to NULL
end;
0
 

Author Comment

by:bobbysdog
ID: 36517591
Yaaaay

Right - the solution was to make it NULL

I used this line to do it:

ADOTable1.FieldValues['KidsName'] := Null;

Open in new window

0
 

Author Closing Comment

by:bobbysdog
ID: 36517593
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

16 Experts available now in Live!

Get 1:1 Help Now