Go To Next Record On Subform from another Form (1 Viewer)

GregAcc

New member
Local time
Today, 18:13
Joined
Jun 25, 2020
Messages
13
All,

I have been struggling for a couple of days now with what should be a very simple procedure.


I have one main form (frmHead) where I entry the main data.

In the main form is also subform (frmTransSub), where additonal data are entered.

Then I have a third »VAT« form primarily for just calculation purposes with one command button on it.


In order to move to the next Record in a subform (frmTransSub) I am trying to use a command button on a Form VAT to make that action.

I can successfully give focus to the subform with Forms!frmHead!frmTransSub.SetFocus.

However, the code doesn’t want to go to the next record in a subform, but it only move ID in the current VAT form instead??

How can I go to the next record in my Subform. How can I adjust the code to do that??


Code:
Option Compare Database
Option Explicit

Private Sub NextRecordSub_Click()

     Forms!frmHead!frmTransSub.SetFocus
    DoCmd.GoToRecord , , acNext
    
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:13
Joined
Oct 29, 2018
Messages
21,473
Hi. How did you verify you were able to set the focus to the subform. If you say because you didn't get an error message, that probably meant the focus may or may not be where you expect it to be. The usual approach is to set the focus to the main form first, then send the focus to the subform.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Feb 19, 2002
Messages
43,270
Automating forms is not the best way to process a set of records. It is far easier to simply open a recordset. Create a query that returns the set of records you want and either use an action query to update the records or use a DAO or ADO recordset to iterate through the records one at a time.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:13
Joined
May 7, 2009
Messages
19,242
try this code:
Code:
Option Compare Database
Option Explicit

Private Sub NextRecordSub_Click()
    On Error Resume Next
    Forms!frmHead.SetFocus
    Forms!frmHead!frmTransSub.SetFocus
    DoCmd.GotoRecord
End Sub
 
Last edited:

GregAcc

New member
Local time
Today, 18:13
Joined
Jun 25, 2020
Messages
13
try this code:
Code:
Option Compare Database
Option Explicit

Private Sub NextRecordSub_Click()
    On Error Resume Next
    Forms!frmHead.SetFocus
    Forms!frmHead!frmTransSub.SetFocus
    DoCmd.GotoRecord
End Sub
 

Users who are viewing this thread

Top Bottom