0

任何人都可以帮助我努力完成最终结果:

我有一个未绑定的主窗体,一个绑定的子窗体,有两个表 Masterplant 和 PlantTransaction。

当我编辑一条记录时,它显示在主窗体上,当我保存记录时,它必须复制子窗体中的现有记录,这可行,但诀窍是新记录中的开放时间必须成为我之前记录的结束时间,一切正常,只是以前的关闭时间记录中没有显示营业时间,并且 TransactionID 是一个数字字段,必须使用不同的 TransactionID 编号自动递增。任何帮助将不胜感激,在此先感谢!!!

下面的代码:

Private Sub cmdSave_Click()
Dim strSQL As String
Dim rst As DAO.Recordset
If IsNull(txtOpeningHRS) Then
  Set rst = Me.RecordsetClone
  If rst.RecordCount > 0 Then
    If Me.NewRecord Then
      rst.MoveLast
    Else
      rst.Bookmark = Me.Bookmark
      rst.MovePrevious
    End If
    txtOpeningHRS = rst!CloseHrs
  End If
End If

If IsNull(Me.TransactionID) Or Me.TransactionID = 0 Then
  Me.TransactionID = Nz(DMax("TransactionID", "PlantTransaction") + 1, 1234)
End If

strSQL = "INSERT INTO PlantTransaction(TransactionID, [Plant Number], Opening_Hours, 
[TransactionDate], [FuelConsumption], [Hour Meter Replaced], Comments, [Hours Worked]) & _ 
   strSQL & "VALUES(" & Me.txtTranID & ",'" & Me.txtPlantNo & "','" & Me.txtOpeningHRS & "',#" & 
   Me.txtTransDate & "#,'" & Me.txtFuelConsFuelHr & "','" & Me.txtHrMtrRep & "','" & Me.txtComments   
   & "','" & Me.txtHrsWorked & "');"
CurrentDb.Execute strSQL
Me.PlantTransactionQuery.Form.Requery
cmdNew_Click
End Sub
4

1 回答 1

0

Set TransactionID to be an AutoNumber data type, this will automatically increment it.

You can also try replacing:

CurrentDb.Execute strSQL
Me.PlantTransactionQuery.Form.Requery

with:

CurrentDb.Execute strSQL
Me!PlantTransactionQuery.Form.RowSource = "Select * from PlantTransaction"
Me.PlantTransactionQuery.Form.Refresh
于 2013-06-21T15:38:09.110 回答