W
Wei Wang
This transaction deals with two linked SQL Server tables from same database,
tblRmaster and tblRitem, which has a master-detail relationship through a
composit key.
transaction code is like this:
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////////
WS.BeginTrans
lngRectNo = DLookup("[Receipt#]", "[tblRect#]") + 1
Set qdef1 = Db.CreateQueryDef("", "INSERT INTO
tblRmaster([EntityNo],[Receipt],[SeqNo],[RecType],[RecDate],[RecTime],[Name]
,[RecDesc],[RecQty],[RecTotal],[RecCode],[TransAmt],[CheckNo],[AmtTend],[Cas
e#],[CtCode],[Year],[CtDiv],[Seq#],[PreNumb],[PartyCode],[PartyNumber],[OPNA
ME],[Bond],[BaseFine]) " & _
"SELECT [EntityNo]," & lngRectNo &
",[SeqNo],[RecType],[RecDate],[RecTime],[Name],[RecDesc],[RecQty],[RecTotal]
,[RecCode],[TransAmt],[CheckNo],[AmtTend],Case#],[CtCode],[Year],[CtDiv],[Se
q#],[PreNumb],[PartyCode],[PartyNumber],[OPNAME],[Bond],[BaseFine] FROM
tblRmasterTemp ORDER By SeqNo")
qdef1.Execute
Set qdef2 = Db.CreateQueryDef("", "INSERT INTO tblRitem (EntityNo,
Receipt, SeqNo, RecType, FundType, FundDesc, TransAmt, DebitCredit,
RectAcct, DisbAcct, VendorNumb, RecDate, RecCode, PayCode, SumDetail,
OPNAME, CalCode) " & _
"SELECT EntityNo, " & lngRectNo & ", SeqNo, RecType,
FundType, FundDesc, TransAmt, DebitCredit, RectAcct, DisbAcct, VendorNumb,
RecDate, RecCode, PayCode, SumDetail, OPNAME, CalCode " & _
"FROM tblRitemNew")
qdef2.Execute
WS.CommitTrans
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////
if I don't use transaction, the code will work.
if I use transaction, the code qdef2.Execute gave error message
"ODBC--Insert on a linked table 'tblRitem' failed".
If I remove the relationship between those two tables, the code will work.
tblRmaster and tblRitem, which has a master-detail relationship through a
composit key.
transaction code is like this:
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////////
WS.BeginTrans
lngRectNo = DLookup("[Receipt#]", "[tblRect#]") + 1
Set qdef1 = Db.CreateQueryDef("", "INSERT INTO
tblRmaster([EntityNo],[Receipt],[SeqNo],[RecType],[RecDate],[RecTime],[Name]
,[RecDesc],[RecQty],[RecTotal],[RecCode],[TransAmt],[CheckNo],[AmtTend],[Cas
e#],[CtCode],[Year],[CtDiv],[Seq#],[PreNumb],[PartyCode],[PartyNumber],[OPNA
ME],[Bond],[BaseFine]) " & _
"SELECT [EntityNo]," & lngRectNo &
",[SeqNo],[RecType],[RecDate],[RecTime],[Name],[RecDesc],[RecQty],[RecTotal]
,[RecCode],[TransAmt],[CheckNo],[AmtTend],Case#],[CtCode],[Year],[CtDiv],[Se
q#],[PreNumb],[PartyCode],[PartyNumber],[OPNAME],[Bond],[BaseFine] FROM
tblRmasterTemp ORDER By SeqNo")
qdef1.Execute
Set qdef2 = Db.CreateQueryDef("", "INSERT INTO tblRitem (EntityNo,
Receipt, SeqNo, RecType, FundType, FundDesc, TransAmt, DebitCredit,
RectAcct, DisbAcct, VendorNumb, RecDate, RecCode, PayCode, SumDetail,
OPNAME, CalCode) " & _
"SELECT EntityNo, " & lngRectNo & ", SeqNo, RecType,
FundType, FundDesc, TransAmt, DebitCredit, RectAcct, DisbAcct, VendorNumb,
RecDate, RecCode, PayCode, SumDetail, OPNAME, CalCode " & _
"FROM tblRitemNew")
qdef2.Execute
WS.CommitTrans
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////
if I don't use transaction, the code will work.
if I use transaction, the code qdef2.Execute gave error message
"ODBC--Insert on a linked table 'tblRitem' failed".
If I remove the relationship between those two tables, the code will work.