Solved Control subform record selection from parent form button. (1 Viewer)

Jarichardusa

New member
Local time
Today, 15:08
Joined
May 23, 2020
Messages
19
I have a form with a subform. Both are built off of the same query. Search box at top finds customer, parent form displace all the customer data, subform displays order data. Subform is set to visible false until button is pressed on parent from to add a new order. When subform becomes visible after pressing this button it is pre-populated with the data from whatever the last order was. I can add a button on the subform for go to to new record to add a new one, but that’s just too many steps. I’d like to knowing there is a way to have my button which makes the subform visible also automatically set the subform data to a new record. I know if it was opening a new form I could simply do it on the on load event, but being subform that’s already there, just invisible, it’s not actually loading, so I’m not sure how to do this. If I try to just blank those boxes out to add new data it just overwrites the old data and doesn’t actually create a new order. Thank you.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:08
Joined
Oct 29, 2018
Messages
21,469
Hi. Welcome to AWF!

Have you tried using GoToRecord?
 

Jarichardusa

New member
Local time
Today, 15:08
Joined
May 23, 2020
Messages
19
Hi. Welcome to AWF!

Have you tried using GoToRecord?
Yes, I did that in a button on the subform, and that works just fine. It if a user clicks a button to add a new order which brings visible the subform, I don’t want them to then have to click another button to make the new record. I want them to hit the one button, at which point the subform comes visible ready to enter the information. Doing that on the parent form as it is right. Law creates an entirely new record, customer and all. All I want a new record in is the order attached to that customer, that information is in the subform in order to maintain that 1-many relationship.
 

June7

AWF VIP
Local time
Today, 11:08
Joined
Mar 9, 2014
Messages
5,470
Form and subform should not be based on same query.

Button would have to make subform visible, set focus to subform, then go to new record row. Example:

Me.ctrRates.Visible = True
Me.ctrRates.SetFocus
DoCmd.GoToRecord , , acNewRec
 

Jarichardusa

New member
Local time
Today, 15:08
Joined
May 23, 2020
Messages
19
Hi. Welcome to AWF!

Have you tried using GoToRecord?
Yes, I did that in a button on the subform, and that works just fine. It if a user clicks a button to add a new order which brings visible the subform, I don’t want them to then have to click another button to make the new record. I want them to hit the one button, at which point the subform comes visible ready to enter the information. Doing that on the parent form as it is right. Law creates an entirely new record, customer and all. All I want a new record in is the order attached to that customer, that information is in the subform in order to maintain that 1-many relationship.
Form and subform should not be based on same query.

Button would have to make subform visible, set focus to subform, then go to new record row. Example:

Me.ctrRates.Visible = True
Me.ctrRates.SetFocus
DoCmd.GoToRecord , , acNewRec

Thank you, I was able to get that to work. About the single query, I am very new to access and it seemed like the way to do it to get all the information I wanted onto one form from 2 different tables.
 

onur_can

Active member
Local time
Today, 12:08
Joined
Oct 4, 2015
Messages
180
Hello
You should first focus on the subform, then go to the New record with the help of DoCmd.
Code:
Me.SubFormName.SetFocus
DoCmd.GotoRecord ,"SubFormName",acNewRecord
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:08
Joined
Oct 29, 2018
Messages
21,469
Yes, I did that in a button on the subform, and that works just fine. It if a user clicks a button to add a new order which brings visible the subform, I don’t want them to then have to click another button to make the new record. I want them to hit the one button, at which point the subform comes visible ready to enter the information. Doing that on the parent form as it is right. Law creates an entirely new record, customer and all. All I want a new record in is the order attached to that customer, that information is in the subform in order to maintain that 1-many relationship.


Thank you, I was able to get that to work. About the single query, I am very new to access and it seemed like the way to do it to get all the information I wanted onto one form from 2 different tables.
Hi. Glad to hear you got it to work using GoToRecord. Good luck with your project.
 

June7

AWF VIP
Local time
Today, 11:08
Joined
Mar 9, 2014
Messages
5,470
But you have a form/subform arrangement, not a single form. Main form should have parent records and subform dependent records. If you include dependent records (the 'many' side) on main form then you 'duplicate' the parent info.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:08
Joined
Feb 19, 2002
Messages
43,266
the only reason for using a main form/subform is if you wanted to show the customer as well as his EXISTING orders. If you never use this form to show existing orders, do not build it this way. The typical way to build an Order form is to have a combo on the order header that allows you to select a customer. Selecting a customer will auto populate the relevant customer fields. Make sure they are locked so you don't accidentally change them on this form. Then the subform should show the items on this order.
 

Users who are viewing this thread

Top Bottom