Hi, I have a form that contains a subform. The Main form has a 1 to many releationship with the subform connected by the CLIENTID. On the main form there is a Delete button. This button deletes that record in the main and all related records in the subform. Before the record is deleted I want to copy the record including all related records in the subform to a new table.
I can get the main form and the first record in the subform to copy, but if there is more that one record in the subform with the same clientID it does not copy. Iam using VBA not SQL. this is my code :
Please what am I doing wrong ????
Private Sub cmdDelete_Exit(Cancel As Integer)
Dim SQL As String
Dim dbs As Database
Dim rst As Recordset
Dim stDocName As String
Dim stlinkcriteria As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Deletes", dbOpenDynaset)
Do While Me![CLIENTID] = Forms![Input]![Transaction Subform]![CLIENTID]
With rst
.AddNew
![CLIENTID] = Me![CLIENTID]
![MainTransit] = Me![MainTransit]
![StartDate] = Me![StartDate]
![FName] = Me![FName]
![LName] = Me![LName]
![CName] = Me![CName]
![AmendedDate] = Me![AmendedDate]
![Currency] = Forms![Input]![Transaction Subform]![Currency]
![Transaction Type] = Forms![Input]![Transaction Subform]![Transaction Type]
![Amount] = Forms![Input]![Transaction Subform]![Amount]
![Transit] = Forms![Input]![Transaction Subform]![Transit]
![Frequency] = Forms![Input]![Transaction Subform]![Frequency]
![Days of the Week] = Forms![Input]![Transaction Subform]![Days of the Week]
![Processing Day] = Forms![Input]![Transaction Subform]![Processing Day]
![Dr/Cr] = Forms![Input]![Transaction Subform]![Dr/Cr]
![Post] = Forms![Input]![Transaction Subform]![Post]
![Service Charge] = Forms![Input]![Transaction Subform]![Service Charge]
![Authorized By] = Forms![Input]![Transaction Subform]![Authorized By]
![Comments] = Forms![Input]![Transaction Subform]![Comments]
![Institute] = Forms![Input]![Transaction Subform]![Institute]
![Name of Customer to be Credited] = Forms![Input]![Transaction Subform]![Name of Customer to be Credited]
![TransationID] = Forms![Input]![Transaction Subform]![TransationID]
.Update
End With
DoCmd.GoToRecord , , acNext, 1
Loop
stDocName = "deletesfrm"
stlinkcriteria = "forms![Input] = " & " '" & Forms![Input]![Transaction Subform]![CLIENTID] & " '"
DoCmd.OpenForm stDocName, , , stlinkcriteria
I can get the main form and the first record in the subform to copy, but if there is more that one record in the subform with the same clientID it does not copy. Iam using VBA not SQL. this is my code :
Please what am I doing wrong ????
Private Sub cmdDelete_Exit(Cancel As Integer)
Dim SQL As String
Dim dbs As Database
Dim rst As Recordset
Dim stDocName As String
Dim stlinkcriteria As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Deletes", dbOpenDynaset)
Do While Me![CLIENTID] = Forms![Input]![Transaction Subform]![CLIENTID]
With rst
.AddNew
![CLIENTID] = Me![CLIENTID]
![MainTransit] = Me![MainTransit]
![StartDate] = Me![StartDate]
![FName] = Me![FName]
![LName] = Me![LName]
![CName] = Me![CName]
![AmendedDate] = Me![AmendedDate]
![Currency] = Forms![Input]![Transaction Subform]![Currency]
![Transaction Type] = Forms![Input]![Transaction Subform]![Transaction Type]
![Amount] = Forms![Input]![Transaction Subform]![Amount]
![Transit] = Forms![Input]![Transaction Subform]![Transit]
![Frequency] = Forms![Input]![Transaction Subform]![Frequency]
![Days of the Week] = Forms![Input]![Transaction Subform]![Days of the Week]
![Processing Day] = Forms![Input]![Transaction Subform]![Processing Day]
![Dr/Cr] = Forms![Input]![Transaction Subform]![Dr/Cr]
![Post] = Forms![Input]![Transaction Subform]![Post]
![Service Charge] = Forms![Input]![Transaction Subform]![Service Charge]
![Authorized By] = Forms![Input]![Transaction Subform]![Authorized By]
![Comments] = Forms![Input]![Transaction Subform]![Comments]
![Institute] = Forms![Input]![Transaction Subform]![Institute]
![Name of Customer to be Credited] = Forms![Input]![Transaction Subform]![Name of Customer to be Credited]
![TransationID] = Forms![Input]![Transaction Subform]![TransationID]
.Update
End With
DoCmd.GoToRecord , , acNext, 1
Loop
stDocName = "deletesfrm"
stlinkcriteria = "forms![Input] = " & " '" & Forms![Input]![Transaction Subform]![CLIENTID] & " '"
DoCmd.OpenForm stDocName, , , stlinkcriteria