M
mhmaid
hi
I have a db which has same idea as the sample db expenses where there are
three main tables
patients
expense reports
expense details
now , I am trying to use the following code to duplicate record in both the
main form and the subform ( exactly as in the above mentioned sample) which
is available on microsoft site
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.for expense reports
Dim lngID 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
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !PATIENTID
'Duplicate the related records: append query.
If Me.[Patients Subform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [Expense Reports main] ( patientid,
BatchId, BatchNumber, BatchDate, DocumentType, Cpv, CpvDate,
EntryReferenceId, EntryReferenceAmount, ROE, FcAmountXR, Currency,
TransactionDate, LastUpdateby, ChqNo, PostingRestriction ) " & _
"SELECT " & lngID & " As NewID, BatchId, BatchNumber,
BatchDate, DocumentType, Cpv, CpvDate, EntryReferenceId,
EntryReferenceAmount, ROE, FcAmountXR, Currency, TransactionDate,
LastUpdateby, ChqNo, PostingRestriction " & _
"FROM [Expense reports main] WHERE patientid = " &
Me.PATIENTID & ";"
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
but the subform which is "employees subform" in the sample has two tables as
source.
what should i do to make the code duplicate for the 3 tables.
note:actully , i have tried using the code for the firts two tables only,
just to test , but unforutnatly i get error in the line:
lngID = !PATIENTID
saying invalide use of null
hope someone can help with this.
as i said , my db is only a developed copy of the sample db " expenses"
I have a db which has same idea as the sample db expenses where there are
three main tables
patients
expense reports
expense details
now , I am trying to use the following code to duplicate record in both the
main form and the subform ( exactly as in the above mentioned sample) which
is available on microsoft site
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.for expense reports
Dim lngID 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
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !PATIENTID
'Duplicate the related records: append query.
If Me.[Patients Subform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [Expense Reports main] ( patientid,
BatchId, BatchNumber, BatchDate, DocumentType, Cpv, CpvDate,
EntryReferenceId, EntryReferenceAmount, ROE, FcAmountXR, Currency,
TransactionDate, LastUpdateby, ChqNo, PostingRestriction ) " & _
"SELECT " & lngID & " As NewID, BatchId, BatchNumber,
BatchDate, DocumentType, Cpv, CpvDate, EntryReferenceId,
EntryReferenceAmount, ROE, FcAmountXR, Currency, TransactionDate,
LastUpdateby, ChqNo, PostingRestriction " & _
"FROM [Expense reports main] WHERE patientid = " &
Me.PATIENTID & ";"
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
but the subform which is "employees subform" in the sample has two tables as
source.
what should i do to make the code duplicate for the 3 tables.
note:actully , i have tried using the code for the firts two tables only,
just to test , but unforutnatly i get error in the line:
lngID = !PATIENTID
saying invalide use of null
hope someone can help with this.
as i said , my db is only a developed copy of the sample db " expenses"