Can't make program go to new record in sub form

ellenr

Registered User.
Local time
Yesterday, 19:06
Joined
Apr 15, 2011
Messages
400
When the order# is selected, it opens Orders form to the correct order, then goes to bound Order Sub form properly (which contains the order details). It always goes to the sub form's first record, not new record, even though the sub form's on Open event directs it to.
Edit: After I execute a go to order sub form, it receives control but never executes the on Open event. I moved the go to control, new macro instruction to the on Focus event but that isn't executed, either.
 
Last edited:
You can try setting the focus to the subform and then execute the GoToRecord acNewRec command.
 
When I do that, it says "You can't go to the specified record. You may be at the end of a record set." I assume it is talking about the main form and not the subform.
 
When I do that, it says "You can't go to the specified record. You may be at the end of a record set." I assume it is talking about the main form and not the subform.
Did you set the focus to the subform first? Can you show us your code, please?
 
Setting focus on a Textbox/Control on the subform from the main Form is a two-step process. Once you set focus to the subform you can use that focus event to move to a new Record. The details are there in the following link:
Setting Focus on a Field inside a subform.
 
Code from the Order Popup wherein the order number is chosen in a combo:

Code:
DoCmd.Minimize    'OrderPopup
    DoCmd.OpenForm "Orders", acNormal, "", "", , acNormal
    DoCmd.Maximize
    DoCmd.GoToControl "text0"    'Order number
    DoCmd.FindRecord Forms!orderpopup!Combo3, acEntire, False, , False, acCurrent, True
    DoCmd.GoToControl "[order subform]"

When it gets to the sub form, the on Focus macro goes to record new, but it doesn't execute. Cursor is on first record
 
Code from the Order Popup wherein the order number is chosen in a combo:

Code:
DoCmd.Minimize    'OrderPopup
    DoCmd.OpenForm "Orders", acNormal, "", "", , acNormal
    DoCmd.Maximize
    DoCmd.GoToControl "text0"    'Order number
    DoCmd.FindRecord Forms!orderpopup!Combo3, acEntire, False, , False, acCurrent, True
    DoCmd.GoToControl "[order subform]"

When it gets to the sub form, the on Focus macro goes to record new, but it doesn't execute. Cursor is on first record
Hmm, I don't see in that code you just posted where you execute a GoToRecord acNewRec like I suggested. How exactly are you sending the subform to the new record? GoToControl only sets focus to it.
 
Hmm, I don't see in that code you just posted where you execute a GoToRecord acNewRec like I suggested. How exactly are you sending the subform to the new record? GoToControl only sets focus to it.
When I do that, it says "You can't go to the specified record. You may be at the end of a record set." I assume it is talking about the main form and not the subform. That is why I put the gotorecord new in the on focus event in the subform.
 
Setting focus on a Textbox/Control on the subform from the main Form is a two-step process. Once you set focus to the subform you can use that focus event to move to a new Record. The details are there in the following link:
Setting Focus on a Field inside a subform.
When I change the focus line:

Code:
'DoCmd.GoToControl "[order subform]"
    Me.[Orders].[order subform].SetFocus

I get error: "Program can't find the field "|1" referred to in your expression." I have no such field in any expression.
 
When I change the focus line:

Code:
'DoCmd.GoToControl "[order subform]"
    Me.[Orders].[order subform].SetFocus

I get error: "Program can't find the field "|1" referred to in your expression." I have no such field in any expression.
Try:
Code:
Me.[order subform].SetFocus
 

Users who are viewing this thread

Back
Top Bottom