ClaraBarton
Registered User.
- Local time
- Today, 14:35
- Joined
- Oct 14, 2019
- Messages
- 810
I have a table of transactions.
When I transfer money from one account to another I need 2 transactions: debit to one account and credit to the other.
After Much Much messing I've decided I need a self-referencing table with a bridge between them
Everything I've read says I need a subform with the bridge table for the transfer. The subform is linked by TransactionID and fTransactionID.
Here is where I've repeatedly failed.
This is what I want:
This is the data in the subform (the tblMatch is an alias of tblTransactions):
This is the code to add the second record the to the junction table.
So far, no joy. The fMatchID remains blank. I've tried using TransactionID from tblMatch but it just repeats the ID from the Main form.
Does any of this make sense? What is the proper way to do this simple thing?
When I transfer money from one account to another I need 2 transactions: debit to one account and credit to the other.
After Much Much messing I've decided I need a self-referencing table with a bridge between them
Everything I've read says I need a subform with the bridge table for the transfer. The subform is linked by TransactionID and fTransactionID.
Here is where I've repeatedly failed.
This is what I want:
This is the data in the subform (the tblMatch is an alias of tblTransactions):
This is the code to add the second record the to the junction table.
Code:
Private Sub Form_AfterUpdate()
Dim strWhere As String
Dim strSql As String
Dim lngCount As Long
Dim PTID As Long
Dim MTID As Long
PTID = Me.Parent.TransactionID
MTID = Me.fMatchID
'criteria string for the compound key fields
strWhere = StringFormatSQL("fTransactionID = {0} and fMatchID = {1}", PTID, MTID)
lngCount = DCount("*", "tblTransferConnect", strWhere)
If lngCount < 1 Then
'Add match to junction table
strSql = StringFormatSQL("INSERT INTO tblTransferConnect(fTransactionID, fMatchID)" & _
" VALUES ({0}, {1});", MTID, PTID)
SQLExecute strSql
Else
Exit Sub
End If
End Sub
Does any of this make sense? What is the proper way to do this simple thing?