Hey Folks, brand new to this forum, Please be kind. LOL
I have a form with a button on it the when pressed takes the data from the fields of the form and automatically generates a NEW record. for example:
Record 1
UNIQUE ID Field: 000001 (auto generated)
Field 1 (first name): Bob
Field 2 (last name): Barker
Field 3 (id): 1
When the DUPLICATE button is pressed the following occurs:
Record 2
UNIQUE_ID Field: 000002 (auto generated)
Field 1 (first name): Bob
Field 2 (last name): Barker
Field 3 (id): 1
What I would like to happen is that when the DUPLICATE button is pressed i get the following
Record 2
UNIQUE_ID Field: 000002 (auto generated)
Field 1 (first name): Bob
Field 2 (last name): Barker
Field 3 (id): 2
So essentially 3 things need to happen
1) New record is generated based on duplicating the existing record
2) A variable needs to be created to be used in an update query which auto increments field 3 by a value of 1
for example: SET NEW_ID = (SELECT id FROM myTABLE WHERE UNIQUE_ID = MyFormValue) +1
3) an update query will then run to update field 3 based on step two above
Here is the current code that duplicates the records using all of the current record data WITHOUT incrementing the id by 1.
NOTE: Me.BatchNumber is the number we'd like incremented by 1. labeled as Field 3 (id) from my above example
NOTE: Me.BatchID is the UNQUIE_ID that gets created when the record is duplicated
NOTE: There is some code following rsNewBatch_Update which is being used for adding additional data associated in a SUB-FORM on the form page. I would suspect that the new code for what Im trying to do would happen just before this code.
Code:
Private Sub cmdDupBatch_Click() Dim BID As Long
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
'DoCmd.DoMenuItem
Dim strsql As String
Dim db As Database
Dim rs, newrs As Recordset
Dim rsNewBatch As Recordset
Dim rc, looper As Integer
Set db = CurrentDb
Set rsNewBatch = db.OpenRecordset("Batch Master")
rsNewBatch.AddNew
rsNewBatch("ProductCategory") = Me.cboCategory
rsNewBatch("Batchnumber") = Me.BatchNumber
rsNewBatch("productdesc") = Me.ProductDesc
rsNewBatch("CodeNumber") = Me.CodeNumber
rsNewBatch("customer_number") = Me.cboCus
rsNewBatch("specialinstructions") = Me.SpecialInstructions
rsNewBatch("viscometer") = Me.ZahnCupUsed
rsNewBatch("totlbsinbatch") = Me.txtPounds
rsNewBatch("weightpergallon") = Me.WeightPerGallon
'rsnewbatch("costperpound")=me
rsNewBatch("master") = 2
rsNewBatch.Update
rsNewBatch.Bookmark = rsNewBatch.LastModified
BID = rsNewBatch("BatchID")
strsql = "SELECT * FROM [Batch Ingredients] WHERE BatchID" & "=" & Me.BatchID
Set rs = db.OpenRecordset(strsql)
'rs.MoveFirst
'rs.MoveLast
'rc = rs.RecordCount
Set newrs = db.OpenRecordset("Batch Ingredients")
rs.MoveFirst
While Not rs.EOF
newrs.AddNew
newrs![BatchID] = BID
newrs![RawMaterial] = rs![RawMaterial]
newrs![Percentof100] = rs![Percentof100]
newrs![PoundsReqInBatch] = rs![PoundsReqInBatch]
newrs![ActualAddition] = rs![ActualAddition]
newrs![NewPercent] = rs![NewPercent]
newrs![MixOrder] = rs![MixOrder]
newrs![ExtendedCostofProduct] = rs![ExtendedCostofProduct]
newrs.Update
rs.MoveNext
Wend
Me.Requery
End Sub