cannot insert value null into column

  • Thread starter Thread starter Geraldine Hobley
  • Start date Start date
G

Geraldine Hobley

Hello,
I have a form that is bound to a table called
MyProject, The form has two fields CmbIndex bound to
MyIndex and ProjectName (unbound). When I tab off the
cmbIndex field I get the following error message.

Cannot insert value NULL into column areaindex.

areaindex is another column in the project table which is
an int column not allowing nulls. I don't want the column
to allow nulls so how can I avoid this error happening.

Regards
Geraldine
 
Two possible suggestions:
1. In form design mode right-click on the combobox and
select properties. On the Data tab enter a default value
of 0.
OR
2. Use the Nz() function. This will replace a Null value
with whatever comes after the comma. Maybe do something
like: (Form design - View> Code)

sub cmbIndex_LostFocus()
cmbIndex = Nz(cmbIndex,0) 'Replace Null value w/zero
end sub

See Access help for more information about entering a
default value and the Nz() function.

Hope this helps.
 
Geraldine Hobley said:
Hello,
I have a form that is bound to a table called
MyProject, The form has two fields CmbIndex bound to
MyIndex and ProjectName (unbound). When I tab off the
cmbIndex field I get the following error message.

Cannot insert value NULL into column areaindex.

areaindex is another column in the project table which is
an int column not allowing nulls. I don't want the column
to allow nulls so how can I avoid this error happening.

Is it your intent to add entries to the table? That is what happens if you
are using a bound form and bound controls.

If you are adding records to a table via a form then all fields that do not
allow Nulls must be included on your form (so you can make an entry) or
they must have a default value assigned at the table level. If your
control cmbIndex is last in the TabOrder then the form will attempt to move
to then next record when you tab out of it. In a bound form that causes
the record you were on to save. Since you have left a required field Null,
the error is thrown.
 
Back
Top