Delete row from Access junction table via form

微笑、不失礼 提交于 2019-12-11 11:44:34

问题


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:

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

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?


回答1:


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].




回答2:


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.



来源:https://stackoverflow.com/questions/16531496/delete-row-from-access-junction-table-via-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!