• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Empty field problem

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
icekalt
Asked:
icekalt
  • 3
1 Solution
 
coondog091800Commented:
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
 
coondog091800Commented:
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
 
icekaltAuthor Commented:
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
 
coondog091800Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now