We help IT Professionals succeed at work.

Subform to populate text field on main form.

thefourthwm asked
Last Modified: 2010-05-18
I am just leaning access so detailed steps to the code would be helpful.  

Basically I have a text field "txt1" that populates my main table with numbers that either enter or take off two subforms "subform1" &"subform2" depending on the response that i need to give. I have queried  the subforms to look up the info that i need based on a "combobox1"  

Is there a code for when i add a new line to either subform1 or subform2 to have my text field auto populate with the number i entered in.  There will never be a case when on the same record i would enter a number into subform1 and subform2. there are two  fields in my subforms the first one is the new numbers I want to populate the text box and the second is the parent field that sets the criteria this field is hidden.  

Any help or advice would be appreciated! Thank You!
Watch Question

Saving (or moving to the mainform) when you enter a new record can be tricky when the row hasn´t been saved as the user can cancel the dataentry....
I normally use the subform´s OnCurrent event to move a value of a selected row to the mainform with:

Parent.txt1 = me.enteredfieldname

This will work when you select a (saved) record in a subform and when you have two subforms, just add the code to both. When you want to automate the selection of a newly entered row, then just make sure that the subform show´s the most recent entered row as the first entry and after saving a new record the txt1 will get the value automatically.

Detailed enough ?



Nic you have not let me down yet the data base is coming together and i am learning a lot.  

I had some problems, but we are on the right track...heres what happens.  the code worked to link the subforms selected field to my txtbox.  but i have two problems i was hopeing you could help me with.  1) when i scroll to the next record and then scroll back the textbox defaults back to the first field in the subform.  2) when i open the main form i get an error <runtime error '-2147352567 (80020009)': You cant assign a value to this object>

how can i keep the number in the text box from changing to the first field in the sub form everytime i scroll thru the records I need to keep it the same once its selected (i will aslo be assigning numbers to this field that are not in the subforms so it is important that these numbers do not change). also what is bringing about the error?  One last thing, i know you said it was tricky but is it possible to add new numbers to the subform that will fill out my txtbox?

You are the master, Thanks!
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks Nic it worked perfectly!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.