从一个未绑定的表单 vba 访问添加多条记录
Posted
技术标签:
【中文标题】从一个未绑定的表单 vba 访问添加多条记录【英文标题】:Adding multiple records from one unbound form vba access 【发布时间】:2016-06-10 20:27:11 【问题描述】:我有一个未绑定的表单,我可以在其中输入 Order 1
、Order 2
、Order 3
的值。使用一个名为“SAVE_LOAD”的按钮,我想将它输入到一个表“LOAD DATA ENTRY”中,Order 1
将创建一个记录行,Order 2
将创建第二行,依此类推。到目前为止,我使用了以下on_click
事件,但它只为Order 1
添加了一行。您如何将其余订单添加为单独的行?请帮助我是新手。
Private Sub SAVE_LOAD_Click()
InsSQL = "INSERT INTO [LOAD DATA ENTRY] ( [ORDER NO], [OPERATION NAME], [SH SPEC], [FINISHED ITEM NO], [FINISHED ITEM DESCRIPTION], [ORDER QTY], [VACUUM EQUIPMENT], [LOAD], [LOAD QTY], [LOAD RACKING], [NO OF BASKETS], [BASKET PLACEMENT], [LOT BASKET AND SAMPLES], [MAX WEIGHT], [ACTUAL WEIGHT], [LOAD DAILY ID]) " & _
" Values ('" & Me.ORDER_NO_1 & "','" & Me.OPERATION_NAME_1 & "','" & Me.HT_SPEC_1 & "','" & Me.FINISHED_ITEM_NO_1 & "','" & Me.FINISHED_ITEM_DESCRIPTION_1 & "','" & Me.ORDER_QTY_1 & "','" & Me.VACUUM_EQUIPMENT_1 & "','" & Me.LOAD_NUMBER_ID & "','" & Me.LOAD_QTY_1 & "','" & Me.LOAD_RACKING_1 & "','" & Me.NO_OF_BASKETS_1 & "','" & Me.BASKET_LOCATION_1 & "','" & Me.LOT_BASKET___SAMPLES_1 & "','" & Me.MAX_WEIGHT_1 & "','" & Me.ACTUAL_WEIGHT_1 & "','" & Me.LOAD_DAILY_ID & "')"
【问题讨论】:
最简单(但最难维护)的方法是再重复该行两次。 为什么不把这个订单表格绑定到一张桌子上呢? Access 具有用于多行数据输入的连续表单类型。 【参考方案1】:你可以尝试迭代它:
Dim i as Integer
for i = 1 to 3
InsSQL = "INSERT INTO [LOAD DATA ENTRY] ( [ORDER NO], [OPERATION NAME], [SH SPEC], [FINISHED ITEM NO], [FINISHED ITEM DESCRIPTION], [ORDER QTY], [VACUUM EQUIPMENT], [LOAD], [LOAD QTY], [LOAD RACKING], [NO OF BASKETS], [BASKET PLACEMENT], [LOT BASKET AND SAMPLES], [MAX WEIGHT], [ACTUAL WEIGHT], [LOAD DAILY ID]) " & _
" Values ('" & Me.ORDER_NO_"' & i,'" & Me.OPERATION_NAME_"' & i,'" & Me.HT_SPEC_"' & i,'" & Me.FINISHED_ITEM_NO_"' & i,'" & Me.FINISHED_ITEM_DESCRIPTION_"' & i,'" & Me.ORDER_QTY_"' & i,'" & Me.VACUUM_EQUIPMENT_"' & i,'" & Me.LOAD_NUMBER_ID & "','" & Me.LOAD_QTY_"' & i,'" & Me.LOAD_RACKING"' & i,'" & Me.NO_OF_BASKETS_"' & i,'" & Me.BASKET_LOCATION_"' & i,'" & Me.LOT_BASKET___SAMPLES_"' & i,'" & Me.MAX_WEIGHT_"' & i,'" & Me.ACTUAL_WEIGHT_"' & i,'" & Me.LOAD_DAILY_ID & "')"
next i
【讨论】:
以上是关于从一个未绑定的表单 vba 访问添加多条记录的主要内容,如果未能解决你的问题,请参考以下文章