Go To Next Record On Subform from another Form

GregAcc

New member
Local time
Today, 13:39
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
 
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.
 
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.
 
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:
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

Back
Top Bottom