How do you Populate a field o a form based on a field in another form ?

JJordan

Registered User.
Local time
Today, 16:24
Joined
Jul 25, 2002
Messages
53
How do you Populate a field on a form based on a field in another form ?

I have a form to enter new donations for donors and one of the fields for describing donations is [catagory] and one selection choice is "Gift In Kind". The table for Catagory is Donations. I have another Table named GIK where a decription of any Gift In Kind is to be entered. The Donations and GIK tables linked by the Receipt_Number field in both tables.

I have a form for the GIK table called GIKForm which opens up on the after update event for the catagory field if the user selects "Gift In Kind" But I want it to open up with the Receipt_Number field already populated with the receipt_number from the main form. I see that it is done in a sub form, but do not want to have a subform in the main form. I do not want this form to appear unless the Gift In Kind is selcted.

I know this is basic stuff, but I have looked at the code for the subforms I have and cannot figure out how those forms get the linked field to be populated by the correct data from the main form. I would really like to have the form pop up as a single line item to enter the descrition and have it tied automatically to teh same receipt_number (i.e., not actually have the receipt_Number filed visible on the GIK Form, just know it is the correct receipt number from the main form).
 
Last edited:
JJordan,

Can you post your db file here? (after removing all data and any images, I think there's a limit of 100KB to post here)

It would help me see more quickly what you are trying to do.
 
I must be an Idiot -- it says cannot attach a .db file, only JPEGS, TXT, etc. I can e-mail it to you.
 
If you've got winzip then zip the database first and then attach the zipped file.
 
The file is too big and I cannot figure out how to get it smaller. I have deleted all tables and forms and reports and Queries other than those needed for the two forms at issue, and I have copacted and repaired, but it is still 865K Zipped which is too big.
 
Do you have any images embedded in the two remaining forms?
 
No. I got it down to 632K. Maybe it is all teh COde written behind everything I deleted?
 
Maybe, try deleteing all your macros and VB/VBA code
 
After creating new and importing and deleting I think I have the DB small emough to attach with just the new donations and GIKTable subform.
 

Attachments

Hide Subform (Conditionally)

Rename your GIKTable Subform to GIKTable.

Add your "GIKTable" to the form "New Donations"

and replace the code you have with this


Private Sub Donation_Catagory_AfterUpdate()

If Me![Donation Catagory] <> "Gift In Kind" Then
Me.GIKTable.Visible = False
Else
Me.GIKTable.Visible = True
End If

End Sub


A word of advice, try not to use spaces when you name fields, tables, forms, queries, and so on. It makes writing code difficunt and sometime in instances where the code would work, it might not when you have to refer to names with spaces. The workaround is to use [], e.g. [New Donations] or is it [New_Donations]?? I think the first one will work.

I hope this is what you want. Hope this helps!
 

Attachments

Last edited:
Oops!! I think I missed the mark completely!! You want a synchronized pop-up form to appear if Gift in Kind is choosen!

I did it by hiding and unhiding the subform based on whether Gift in Kind is choosen!!

If I have time to redo this, I'll try!!

Sorry about that!

EDIT: Can't synchronize the two forms since you have to poplulate the GIK table, what you want is to automatically populate the receipt number, right?

EDIT # 2: The best I couls come up with was to have the form open up when GIFT IN KIND is chosen, and then when DescOfGiftInKind has the focus (i.e. you click in the box), than a macro is run.[/B]

Create a macro and use SetValue
Item: Field to set value - Click the button with the three dots and look for the GIK form and then the Receipt Number Field
Expression: Value to be used - Click the button with the three dots and look for the New Donations form and then the Receipt Number Field

Best I've been able to come up with so far....
 
Last edited:
Which one?

Which are you using? The hide subform on main form or the Pop-up and set value macro....

(serves me right to keep editing the same thread..) :p
 
Yes it is. All I wanted to happen was have the SubForm open IF the Catagory field on the main form is set to Gift In Kind and I want the subform's Receipt Number field to be populated with the same receipt number (this is the link between the two tables - Donation table and GIKTable) so when the description is filled out for that donation it is linked by receipt number and all they have to do is type in the description of the gift in kind, not make sure it is for the same "receipt" they are working on.
 
Last edited:
Did you figure this out?

Did you ever figure out how to do this? I am trying to do the same thing...know it must be simple...but can't find any reference to it in the book that I have. Please advise...

Thanks!
 
No, I did not. I am thinking it might work to set the Default Value of the field to the Form field you want it to match, but if you then change the main form, the sub form will not change unless you close and reopen. I have not tried it. There should be an easy way. It works in SubForms, but I cannot find the CODE that makes it work.
 
Last edited:
JJordan,

You CAN have the receipt number in GIKtable form have the same receipt number is in the table Donations

The problem is since you have a many-to-one relationship from GIKTable to Donations, you need to manually enter the receipt number or have code enter it. (The exception being that you have it as a subform in which case it will be in sync with your main form.)

Why do you need a many-to-one relationship anyway? Will you have more than one DescOfGiftInKind for one Donation receipt number?

If not, I suggest adding DescOfGiftInKind to your donations table and you can just use the same logic that I applied to hiding and showing the form to showing/hiding the DescOfGiftInKind textbox and label.

If you DO need many DescOfGiftInKind for one receipt number and you still want the form for GIKTable to pop-up, then you code need to run on open of the form and set the value of the receipt number to the current value of receipt number on the Donations form.

Let me know, and if I can find the time, I'll try to help.
:D
 
Last edited:
Here's your DB file, the one where frmGIKTable pop-up up when Gift In Kind is choosen.

The one problem, is then when if pops up, and you enter a description, you can't close it or save that description till the New Donation record has been saved (i.e created), and that doesn't happen till you press the Save Donation or add a new Donation.

I still think that you should just add the DescOfGiftInKind to the Donation table if you are only going to enter one DescOfGiftInKind for each donation.

I just changed the AfterUpdate code in your New Donations form for Donation Category from

If Me![Donation Catagory] = "Gift In Kind" Then

DoCmd.OpenForm "frmGIKTable"

Else


to

If Me![Donation Catagory] = "Gift In Kind" Then

DoCmd.OpenForm "frmGIKTable", acNormal, "", "[Forms]![New Donations]![Receipt Number]", acAdd, acNormal
Forms!frmGIKTable!RNumber = Forms![New Donations]![Receipt Number]

Else
 

Attachments

Users who are viewing this thread

Back
Top Bottom