Hi i've found this code:
And I think i get how enough of it works to muddle through it, however it assumes the use of a set ID as opposed to an auto-number.
Can someone please explain (in detail as my brain hates programming) how I can remove the code for the ID and replace it (or just leave out enough) with Auto-number details.
Here is my eddited version.
Also my understanding is that the "[recipe details]" should be an append query. I don't know how to make one of those... (I assume it is different from an "update" query?).
Cheers
And I think i get how enough of it works to muddle through it, however it assumes the use of a set ID as opposed to an auto-number.
Can someone please explain (in detail as my brain hates programming) how I can remove the code for the ID and replace it (or just leave out enough) with Auto-number details.
Here is my eddited version.
Code:
Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the subform.
Dim strSql As String 'SQL statement.
Dim RecipeID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
! VersionNumber = Me.VersionNumber
! [Active?] = Me.[Active?]
! ProductCode = Me.ProductCode
! ProductName = Me.ProductName
! RecipeDate = Date
.Update
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark = .LastModified
RecipeID = !OrderID
'Duplicate the related records: append query.
If Me.[S-frmIngredientsInRecipe].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [Recipe Details] (RecipeID, Ing_codeID, [Quantity(g)], QUID ) " & _
"SELECT " & RecipeID & " As NewID, RecipeID, Ing_codeID, [Quantity(g)], QUID " & _
"FROM [Recipe Details] WHERE RecipeID = " & Me. RecipeID & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related records."
End If
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdDupe_Click"
Resume Exit_Handler
End Sub
Also my understanding is that the "[recipe details]" should be an append query. I don't know how to make one of those... (I assume it is different from an "update" query?).
Cheers