且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建表单以在多个表中添加记录

更新时间:2023-11-30 20:13:52

上述设计需要四个子表单.每个子表单都应基于书本ID为链接子项和主字段的联结表,并以相关表为基础的第二个表ID为组合框.

The above design requires four subforms. Each subform should be based on the junction table with book id as the link child and master field and a combo box based on the relevant table for the second table id.

例如,您的第一个子表单是Authors,它基于的表是Libri_Autori

For example, your first subform is Authors, the table it is based on is Libri_Autori

Link Master Field: Id
Link Child Field: SchedaLibro

组合框:

Control Source: SchedaAutore
Row Source : SELECT Id, Nome FROM Autori
Bound Column: 1
Column Count : 2
Column Widths : 0, 2

创建您的书籍表单,然后开始添加子表单,向导将为您完成大部分工作.

Create your book form and then start adding subforms, the wizards will do most of the work for you.

要将记录添加到authors表,您需要将限制到列表"设置为是",并在不在列表中"事件上运行代码.我喜欢使用一个小的弹出表单将项目添加到背景"表中.使用Access 2010可能会更容易,因为您可以设置

To add records to the authors table, you need to set Limit To List to Yes and run code on the Not In List event. I like to use a small pop-out form to add items to the "back ground" tables. This may be easier with Access 2010, because you can set a ListItemsEditForm

1,书籍表单,即将添加子表单.请注意已选中使用控制向导".这是默认设置,因此除非您未选择它,否则应该没问题.

1, The book form, just before adding the subform. Note that Use Control Wizards is selected. This is the default, so unless you unselected it, it should be fine.

添加子表单的各种向导步骤

The various wizard steps for adding a subform

选择子表单字段

选择链接子字段和主字段

Selecting the link child and master fields

显示以黄色突出显示的子窗体控件的窗体和控件属性

The form showing the subform control highlighted in yellow and the control properties

2,添加组合

您可以通过右键单击并自行设置属性来将子窗体向导添加的字段更改为组合.

You can either change the field added by the subform wizard to a combo by right clicking and setting the properties yourself ...

...,或者您可以使用向导删除现有控件并添加组合.第一步是选择组合的类型.

... or you can delete the existing control and add a combo using the wizard. The first step is to choose the type of combo.

第二步是选择表或查询

第三步是选择字段

第四步选择排序顺序,此处不显示,这是第五步,用于设置列宽

Step four chooses the sort order and is not displayed here, this is step five, which is to set the column widths

第六步是设置控制源

您最终将看到一个带有说明属性的组合框

You will end up with a combobox with the properties illustrated

最终表格