MackMan
Registered User.
- Local time
- Today, 06:03
- Joined
- Nov 25, 2014
- Messages
- 174
Hi guys. Last week I submitted the thread ...
http://www.access-programmers.co.uk/forums/showthread.php?t=277992 and from this I wanted to copy one table to another, incrementing the date by any given value. With a lot of help, the desired outcome was reached.
After looking and not finding on Google and so on, I'm trying to copy the tables Related table to another table (again, I'm not worried about DB size, as these will eventually be used as entry at some point) but I keep coming up with the same thing...; Error 3201 - You cannot add or change a record because a related record is required in Table tblBILLSeriesTopLines
This is a little confusing to try and explain, so please bare with me.
Two Tables each ( four in all )
Table One contains the main records, and I can create (and copy as many as I need to table three which hold ALL those records.
Table two contains any sub records of table one where necessary, and I'd like to be able to do the same... Create as many that are necessary as per the main table, and create this in table four (which is related to table three - See diagram.. I hope I've explained better there)
If possible, I'd be grateful if someone could take a look at my SQL's and advise.
The whole WHERE / FROM and ID's are confusing me., and I've no doubt not incuded an ".update" or something, or not set something that I should.
My thought process behind the above was..
Create the necessary records in the primary table, and then create the necessary records in the related table.
As always... I appreciate all your comments and advise. More so, your patience.
http://www.access-programmers.co.uk/forums/showthread.php?t=277992 and from this I wanted to copy one table to another, incrementing the date by any given value. With a lot of help, the desired outcome was reached.
After looking and not finding on Google and so on, I'm trying to copy the tables Related table to another table (again, I'm not worried about DB size, as these will eventually be used as entry at some point) but I keep coming up with the same thing...; Error 3201 - You cannot add or change a record because a related record is required in Table tblBILLSeriesTopLines
This is a little confusing to try and explain, so please bare with me.
Two Tables each ( four in all )
Table One contains the main records, and I can create (and copy as many as I need to table three which hold ALL those records.
Table two contains any sub records of table one where necessary, and I'd like to be able to do the same... Create as many that are necessary as per the main table, and create this in table four (which is related to table three - See diagram.. I hope I've explained better there)
If possible, I'd be grateful if someone could take a look at my SQL's and advise.
The whole WHERE / FROM and ID's are confusing me., and I've no doubt not incuded an ".update" or something, or not set something that I should.
Code:
Private Sub cmdCreate_Click()
Dim strSQL As String
Dim strSQLSub As String
Dim db As Database
Dim i As Integer
Dim NewID As Long
Dim StartDate As Date
Dim z As Double
Dim Intv As String
Dim Every As Double
Dim SubID As Long
If Me.Dirty Then
Me.Dirty = False
End If
Set db = CurrentDb()
NewID = Me.BILLID
SubID = [Forms]![frmBILLEnterDetails]![frmRegisterSplitsPopup].[Form]![BILLSplitID]
StartDate = Me.TransDate
z = Me.RecurCount
Intv = Me.PeriodTypeID
Every = Me.PeriodFreq
For i = 1 To z
strSQL = "INSERT INTO [tblBillSeriesTopLines] ( BillID, AccountID, PayeeID, ChequeNo, TransDate, Category, SubCategory, Credit, Debit, Amount, FixedOrEstimateID, " & _
"TransactionStatus, Flagged, FlagReasonID, TransferToAccountID, TransferFromAccountID, IsTransferYN) " & _
"SELECT " & NewID & " AS NewID, AccountID, PayeeID, ChequeNo," & Format(DateAdd(Intv, (i * Every) - 1, StartDate), "\#mm\/dd\/yyyy\#") & " AS TransDate, Category, " & _
"SubCategory, Credit, Debit, Amount, FixedOrEstimateID, TransactionStatus, Flagged, FlagReasonID, TransferToAccountID, TransferFromAccountID, IsTransferYN " & _
"FROM [tblBILLDetails] WHERE BillID = " & Me.BILLID & ";"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Next i
db.Close
Set db = CurrentDb()
SubID = Me.BILLID
For i = 1 To z
strSQLSub = "INSERT INTO [tblBILLSeriesSplits] ( BillTopLineID, TransDate, Payee, Category, SubCategory, Credit, Debit, Amount, Memo) " & _
"SELECT " & SubID & " AS NewID," & Format(DateAdd(Intv, (i * Every) - 1, StartDate), "\#mm\/dd\/yyyy\#") & " AS TransDate, Payee, Category, SubCategory, Credit, Debit, Amount, Memo " & _
"FROM [TblBillDETAILSSplit] WHERE BillTopLineID = " & NewID & ";"
DBEngine(0)(0).Execute strSQLSub, dbFailOnError
Next i
db.Close
Create the necessary records in the primary table, and then create the necessary records in the related table.
As always... I appreciate all your comments and advise. More so, your patience.