VBA to move to a new record in a subform (1 Viewer)

andy1968

Registered User.
Local time
Today, 03:39
Joined
May 9, 2018
Messages
131
I have code in my form to print preview a report.


I would like to move to a new record in a subform after the report is opened.


I have tried to enter this code at the end of the open report code:


Code:
Me.frmToDoListEntryLinks.SetFocus
DoCmd.GoToRecord , , acNewRec


I get a Run-time error '2046': The command or action 'GoToRecord' isn't available now.




The focus moves to the subform, but that stops on the last record.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
on your form:

docmd.openreport "the report"
docmd.gotorecord,, acNewRec
 

andy1968

Registered User.
Local time
Today, 03:39
Joined
May 9, 2018
Messages
131
Wouldn't that just move to a new record on the main form?


I'm trying to move to a new record on a subform.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
'2x
Me.subformname.setfocus
Me.subformname.setfocus
docmd.gotorecord,, acNewRec
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:39
Joined
Oct 29, 2018
Messages
21,494
Hi. Since we can't see your subform, I'm just gonna ask: Does your subform allow additions?
 

andy1968

Registered User.
Local time
Today, 03:39
Joined
May 9, 2018
Messages
131
Yes, it does.


I tested the code on as a stand alone on the main form and it worked flawlessly.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
Me.frmToDoListEntryLinks.Form.Recordset.AddNew
 

Users who are viewing this thread

Top Bottom