插入更改第一项,而不创建新项

时间:2018-11-06 19:00:33

标签: vba ms-access-2010 insert-into

我正在创建一个访问应用程序,以自动生成产品的序列号。我正在使用insert into命令,它只是更改表的第一个条目,而不是使用已指定的序列号创建一个新条目。当我逐步进行操作时,我可以看到所有条目都具有所需的值,但是执行后,它只会更改第一个序列号。

    Function CreateRFBarrier(pfrm As Object, pValue As String) As Boolean

    Dim db               As Database
    Dim LInsert          As String
    Dim LSerialNumber    As String
    Dim LLoop            As Integer

   On Error GoTo Err_Execute

   Set db = CurrentDb()

   LLoop = 1

  'Create number of records based on BuildQuantity value
   While LLoop <= pfrm.BuildQuantity

     'Get next SerialNumber value (sequential number)
      LSerialNumber = NewItemCode("OD")

      If LSerialNumber = "" Then
       GoTo Err_Execute
      End If

     'Create new record
      LInsert = "Insert into RFBarrier "
      LInsert = LInsert & " VALUES ("
      LInsert = LInsert & "'" & LSerialNumber & "'"
      LInsert = LInsert & ", " & pfrm.WorkOrder
      LInsert = LInsert & ", " & pfrm.BuildQuantity
      LInsert = LInsert & ", " & pfrm.DateCreated & ""
      LInsert = LInsert & ", " & pfrm.CreatedBy & ")"

     db.Execute LInsert, dbFailOnError

     LLoop = LLoop + 1

   Wend

   Set db = Nothing

   CreateRFBarrier = True

   Exit Function

Err_Execute:
   'An error occurred
    CreateRFBarrier = False
    MsgBox "An error occurred while trying to add new RFBarrier serial numbers."

End Function

0 个答案:

没有答案