Lidija Barbaric
asked on
update mainform from subform
First time poster.
Would like a bound field in mainform, donorid_tx, to change its value when I update the subform field DONORID which goes through previously used donors using key DONORID. The donorid_tx on the main form has a its record source as a query with appropriate fields in place.
suggestions keep telling me to change the control source of donorid_tx to reference the subform- I cannot do that because I want the control source to remain tied to the table where this data will go. So confused. Is it a problem that this donorid_tx isn't in another subform with the table it belongs to as a recordsource? (this table is a list of events for which donorid_tx is a number id and not a primary key. DONORID in the subform is a primary key in my table list of donors....
Would like a bound field in mainform, donorid_tx, to change its value when I update the subform field DONORID which goes through previously used donors using key DONORID. The donorid_tx on the main form has a its record source as a query with appropriate fields in place.
suggestions keep telling me to change the control source of donorid_tx to reference the subform- I cannot do that because I want the control source to remain tied to the table where this data will go. So confused. Is it a problem that this donorid_tx isn't in another subform with the table it belongs to as a recordsource? (this table is a list of events for which donorid_tx is a number id and not a primary key. DONORID in the subform is a primary key in my table list of donors....
Can you load up a sample db so we can get a better understand of what it is you are trying to accomplish???
ET
ET
ASKER
Thank you all for the super helpful responses.
I figured it out though I'm not sure how. <so many tries>Code posted below.
Curious as to why the record source for the main form continuously updates/changes as a query the more things I add. What does this mean for the database? Is that something back-end I should never mess with? I know it's a rookie question but a rookie I be.
The donorid_tx is a foreign key and so duplicates are allowed.
The first subform (query based) looks-up previous donors associated and then I wanted to select from this list and transfer data to 2nd subform in order to assign that donor to an instance (in a table). I cannot post, it holds health-sensitive information. However I will post the code below for my onlick event in the first form which correctly transferred the value and verified the transfer.
Again thank you all so much.
Private Sub Command39_Click()
Forms![mainform]![subform1 ]![subform 1fieldtobe transferre d].Value = Forms![mainform]![subform2 ]![subform 2fieldtobe gained].Va lue
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Selected donor for this record" _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
Exit_cmdCancel_Click:
Exit Sub
End If
End Sub
I figured it out though I'm not sure how. <so many tries>Code posted below.
Curious as to why the record source for the main form continuously updates/changes as a query the more things I add. What does this mean for the database? Is that something back-end I should never mess with? I know it's a rookie question but a rookie I be.
The donorid_tx is a foreign key and so duplicates are allowed.
The first subform (query based) looks-up previous donors associated and then I wanted to select from this list and transfer data to 2nd subform in order to assign that donor to an instance (in a table). I cannot post, it holds health-sensitive information. However I will post the code below for my onlick event in the first form which correctly transferred the value and verified the transfer.
Again thank you all so much.
Private Sub Command39_Click()
Forms![mainform]![subform1
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Selected donor for this record" _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
Exit_cmdCancel_Click:
Exit Sub
End If
End Sub
If you don't have a lot of data in the database, it would be good to post the whole thing. Since the data is sensitive, you can obfuscate it. I generally replace all last name fields with just the first letter, and same for all addr1 fields. SSN's I generally change to all zeros. There may be other identifying fields you need to hide but otherwise leave the base data alone since it gives us perspective. Sometimes if there is too much data, I might strip out most of it. That is harder though since RI always gets in the way.
You said that DONORID is the PK. Sounds like donorID_tx is not the FK. Usually the PK and FK names are identical although some people add suffixes suck as donorid_fk.
You said that DONORID is the PK. Sounds like donorID_tx is not the FK. Usually the PK and FK names are identical although some people add suffixes suck as donorid_fk.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
If when you open the child table in DS view and sort on donorid_tx, you see "duplicate" instances of donorid_tx and donorid_tx is NOT the foreign key, then it doesn't belong in the child table.