Hi Graham,
Let's take a step back here. I am making the following assumptions.
Please
tell me if each of them is correct or incorrect, and explain as clearly
as
possible the incorrect ones:
1. You have a one-to-many relationship between tblProjects and
tblTransactions - one project can have many transactions.
Three Tables:
tblProjects :
Fields: ProjectID, Pno, Pname
tblItems:
Fields : ItemID,Itemno,ItemDesc,MfgPartno,Supplier,UOM,StockNo
tblTransactions:
Fields :TransacationID,PID,TranItemID,Location,Qty,DOT,
Type
Relation:
One to Many
tblProjects : ProjectID- PK ~ tblTransactions : PID- FK
One to Many
tblItems : ItemID-PK ~ tblTransactions : TranItemID-FK
Constraint : Referential Integrity Constraint.
2. The primary key of tblProjects is ProjectID and the related foreign
key
in tblTransactions is PID.
Yes
3. Sometimes a user will mistakenly add a new project and then add
transaction records that relate to it.
Yes
4. In such cases you want to delete the entire project but NOT delete
the
related transaction records, instead assigning them to a different
project.
Yes
5. Sometimes a user will add a transaction record to the wrong project,
but
the project is a valid one that should not be deleted.
Yes
6. In such cases, you want to reassign only the incorrectly assigned
transactions to a different project.
Yes
7. You have a main form named "addingfrm" which is bound to
tblProjects.
No. it is bound to tbltransactions. Since I have 2 combo boxes on my
main
form and tbl transactions has PID field that links to the ProjectID in
the
ProjectTable and TranitemID which links to the ItemID of the tblitems.
8. This form contains a subform "final_transubform" which is bound to
tblTransactions.
No. property sheet of my final_transubform reads
Link Master Fields: cmbpno;cmbitemno
cmbpno has the feilds of tblprojects queried as its row source
cmbitemno: has the feilds of tblitems queried as its row source
Link Child Fields: pid;tranitemid - fields from my tbltransaction
9. The subform control that contains final_transubform has
LinkMasterFields
set to ProjectID and LinkChildFields set to PID.
yes
10. You have a dialog form "DELETE_PROJECT" which is intended to
perform
one
of the following actions on the project currently displayed in
"addingfrm":
a) Delete project AND all related transactions
b) Reassign all related transactions to another project then delete
project
c) Reassign one or more transactions to another project and DO NOT
delete the project
There is a button on the adding form which when clicked opens the
DELETE_PROJECT unbound form in a dialog window.
11. This form (DELETE_PROJECT) is unbound - in other words, its
RecordSource
is blank.
Yes
12. The dialog form is opened by clicking a button on your *main* form.
Yes
13. The Click event of the button passes the current ProjectID
(Me.ProjectID) to the form through OpenArgs.
I am confused as to how to code this part !! I have to write a docmd
open
form in the button click event.
14. The Open or Load event of the dialog form is retrieving this value
from
Me.OpenArgs so it knows which project to perform the action on.
Yes
I really appreciate your patience and you taking the time to go step
wise.
I
dont think i am following step 7 & 8 because of the 2 combo boxes on my
main
form which is referring to 2 associated feilds on my subform.
thanks again.
:
Hi Vandy
Let's take a step back here. I am making the following assumptions.
Please
tell me if each of them is correct or incorrect, and explain as
clearly
as
possible the incorrect ones:
1. You have a one-to-many relationship between tblProjects and
tblTransactions - one project can have many transactions.
2. The primary key of tblProjects is ProjectID and the related foreign
key
in tblTransactions is PID.
3. Sometimes a user will mistakenly add a new project and then add
transaction records that relate to it.
4. In such cases you want to delete the entire project but NOT delete
the
related transaction records, instead assigning them to a different
project.
5. Sometimes a user will add a transaction record to the wrong
project,
but
the project is a valid one that should not be deleted.
6. In such cases, you want to reassign only the incorrectly assigned
transactions to a different project.
7. You have a main form named "addingfrm" which is bound to
tblProjects.
8. This form contains a subform "final_transubform" which is bound to
tblTransactions.
9. The subform control that contains final_transubform has
LinkMasterFields
set to ProjectID and LinkChildFields set to PID.
10. You have a dialog form "DELETE_PROJECT" which is intended to
perform
one
of the following actions on the project currently displayed in
"addingfrm":
a) Delete project AND all related transactions
b) Reassign all related transactions to another project then
delete
project
c) Reassign one or more transactions to another project and DO NOT
delete the project
11. This form (DELETE_PROJECT) is unbound - in other words, its
RecordSource
is blank.
12. The dialog form is opened by clicking a button on your *main*
form.
13. The Click event of the button passes the current ProjectID
(Me.ProjectID) to the form through OpenArgs.
14. The Open or Load event of the dialog form is retrieving this value
from
Me.OpenArgs so it knows which project to perform the action on.
Please confirm or correct all of these assumptions and post back.
Don't
worry - we'll get this nailed
--
Graham Mandeno [Access MVP]
Auckland, New Zealand
Hi Graham,
I have followed point 1 & 2 and passed the PID to DELETE_PROJECT
unbound
form. What is happening here is that only the first line Project Id
is
getting passed as open arg to the form.
I want to use the code below to delete the PID and all the related
transaction records from tbltransaction.
strSQL = "Delete from tblTransaction where PID=" &
Me.ProjectID
CurrentDb.Execute strSQL, dbFailOnError
but for that i need to be able to delete the correct PID.
EG;
Tbltransaction.
TransactionID PID Type Qty
235 386 Received 200
236 309 Received 10
237 386 Issued 20
238 312 Recieved 300
What is happening is even say in my main form if the user entered
the
wrong
Project Id for say TransactionID 238. I need to delete that entry.
if i select 238 TransactionID to delete because of wrong PID entered
on
my
main form it still selects 235 TransactionID and passes PID = 386
which
is
the first line no in my transaction table. how to make it point to
the
correct PID for deleting the record.I think i need to refresh the
table
how
to go about doing that.
thanks
:
Hi Vandy
Are you actually *doing* anything with the PID you are passing in
parameter
7? The form you are opening needs to retrieve it from Me.OpenArgs
and
actually *do* something with it.
Did you read my second-to-last message, especially points 1 and 2?
1. Your DELETE_PROJECT form should be unbound (RecordSource is
blank)
2. You can pass the PID to be deleted via OpenArgs (the 7th
parameter
for
OpenForm):
DoCmd.OpenForm "DELETE_PROJECT", , , , , acDialog, Me.PID
or
DoCmd.OpenForm "DELETE_PROJECT", WindowMode:=acDialog,
OpenArgs:=Me.PID