从一个未绑定的表单vba访问添加多个记录

时间:2016-06-10 20:27:12

标签: forms vba ms-access

我有一个未绑定的表单,我可以在其中输入Order 1Order 2Order 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 & "')"

Unbound Form

1 个答案:

答案 0 :(得分:0)

您可以尝试迭代它:

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