Hey there good day can anyone help as i am struggling to finish the end result:
I got a unbound mainform
got a bound subform
got two tables Masterplant and PlantTransaction
When I edit a record it shows on the mainform and when i save the record it must duplicate an existing record in the subform which works but the trick is that the Opening Hours in the new record must become my the Closing Hours of the previous record, everything works its just the Opening Hours does not show from the Closing hours previous record and the TransactionID is a number field that must auto increment with a different TransactionID number any help will be appreciated thanks in advance!!!
Code below:
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