Question

I set up a subform listing stored values from a junction and lookup table. This part is working nicely (I can view all stored entries or add new ones).

Here are my relationships:

enter image description here

And here's the layout of my form showing where I attempted to remove a previously saved association. If I simply delete the contents of the row in the form, Access returns this when I try to save the record: index or primary key cannot contain null value

enter image description here

The SQL to remove a row from a console is straightforward:

DELETE FROM junction_model WHERE cust_id = X AND model_id = Y

Removing a row from the form is proving not to be as straightforward.

Is there a relatively easy way of doing this from the form itself?

Was it helpful?

Solution

Those little squares to the left of the combo boxes (one of which has a "pencil" icon in it, indicating a dirty record) are the "record selectors". Clicking a record selector will select the record, then if you hit Delete the record will be deleted.

It looks like you just deleted the contents of the combo box. When you went to save the (still-existing) record Access objected because the .Value of the combo box was Null, and your Primary Key on the junction table prohibits Null values for [model_id].

OTHER TIPS

For the benefit of others combing back to this:

One option (perhaps more intuitive for the user) is to add a Delete button to your subform. Open the subform in Design view and add a Button from the Controls palette, with control wizard turned on. Command Button Wizard should open - choose 'Record Operations' from the Categories list and 'Delete Record' from the Actions list. The rest of the wizard will customize the look and name of the button.

I'm using a similar form and each row looks like this, with the (X) being a little delete button after the combo box:


Ford Pinto (X)


If deleting is important, I think the button is a much more visible method than clicking the 'record selector' and pressing the delete key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top