Unable to save a record through bound form

V

Vinod

Hi All,

I've create a table Employee, Emp_ID, Product, Comments Where Emp_ID and
Product are imposed with primarykey. i.e., combination of Emp_ID and Product
should not be duplicated.

I've designed a bound form with above said table display as contineuous form.

Header contains product drop down which is populated with master table.
If user selects any product in the top then assigning the product code in
details section with selected product through dropdown change event. If user
selects employe name Emp_ID automatically populated.

In this way I'm trying to add new record.
Giving employee name in first field, Emp_Id retrieved from antother table
based on given employee id, Product contain 'test' which I selected in
header. Till this record is in edit mode. After this I'm moving to second
record there I'm getting following error.

"Index or Primary key can not contain a Null Value".

Please help me how to resolve it.

Advanced Thanks,
~Vins
 
K

Ken Sheridan

The easiest way to do this, which requires no code, would be to use a bound
subform based on your Employee table, in continuous form view, embedded
within an unbound form. Put the combo box from which you can select a
product in the unbound form.

Link the subform to the parent form by making its LinkMasterFields property
the name of the products combo box in the unbound form, and its
LinkChildFields property the name of the Product field in the Employee table.

On the subform, as well as a control bound to the Comments field include a
combo box bound to the Emp_ID field so that you can select an employee from
its drop-down list. You don't need to include a control bound to the Product
field in the subform; a value will be inserted into the underlying field
automatically by the linking mechanism.

Set up the Emp_ID combo box along these lines which will list the names from
a table Employees containing fields Emp_ID, FirstName and LastName :

ControlSource: Emp_ID

RowSource: SELECT Emp_ID, FirstName & " " & LastName FROM Employees
ORDER BY LastName, FirstName;

BoundColum: 1
ColumnCount: 2
ColumnWidths: 0cm;8cm

If your units of measurement are imperial rather than metric Access will
automatically convert the last one. The important thing is that the first
dimension is zero to hide the first column and that the second is at least as
wide as the combo box.

When you select a product in the combo box on the parent form the subform
will show just those rows for that product, and you can insert a new row in
the subform by selecting an employee and entering comments in the blank row
at the bottom of the subform. So long as that employee has not already been
selected for the current product there will be no key violation and the row
will be inserted. If the employee has previously been selected for the
current product then you'll get an error message and the row won't be
inserted into the table.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top