?
Solved

Empty field problem

Posted on 2003-03-19
4
Medium Priority
?
253 Views
Last Modified: 2010-04-04
Hi,

I'm novice at Delphi and have been thrown in the deep end, but perhaps someone has a solution.

I have a set of database edit boxes (DBEdit) and their contents get posted to an Access Database. However, if the operator does not enter any data in them, the following error is given when the contents are posted to the db: 'Key violation. You tried to assign the Null value to a variable that is not a Variant data type.'. I did indicate in the Access database that these fields aren't required and can have zero length.How do I fix this?

Kind regards,

Icekalt.
0
Comment
Question by:icekalt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 1

Expert Comment

by:coondog091800
ID: 8166830
It sounds like you are trying to assign a null value to a primary key.  Even if you have it set to not be required and allow null values it has to have data entered into it.  Set the field where it is not a primary key and it should work.  I usually use an autonumber for the key and get past this problem.

Rich
0
 
LVL 1

Expert Comment

by:coondog091800
ID: 8167228
It sounds like you are trying to assign a null value to a primary key.  Even if you have it set to not be required and allow null values it has to have data entered into it.  Set the field where it is not a primary key and it should work.  I usually use an autonumber for the key and get past this problem.

Rich
0
 

Author Comment

by:icekalt
ID: 8171925
Hi,

Well, the primary key for the table is an autonumber field, and I indicated that the other columns are not required and may have zero length.

I wonder... perhaps Access requires something to be typed in a row before the key for the row is created.

Icekalt
0
 
LVL 1

Accepted Solution

by:
coondog091800 earned 750 total points
ID: 8174594
There does have to be information in a field for it to genereate the random number.  I would put a simple check in the BeforePost event to check for blank fields. If fields are blank then cancel the post and display a message telling the user to enter data and set focus in the first empty dbEdit.

if (dbEdit1.text = '') or (dbEdit2.Text = '') then
  begin
    ShowMessage('Please enter data in all edit boxes');
    dbEdit1.SetFocus;
  end
else
  Table1.Post;  

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

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