Add and Edit VBA for form and relative subforms

E9-Tech

New member
Local time
Today, 04:39
Joined
Apr 28, 2021
Messages
11
I have a main form with a Add command to add a new record and an edit command.
The form has a subform which consequently has a further subform itself with a One to Many relation, all forms and subform are set no additions and no edits in the properties.

So I wrote the code to allow additions and edits:
Code:
Private Sub CmdAdd_Click()
    DoCmd.OpenForm "frmDuties", acNormal, "", "", acAdd
    Forms!frmDuties!CmdEdit.Visible = False
    Forms!frmDuties!DutyDate.SetFocus
    Forms!frmDuties!sfrmRuns.Form.AllowAdditions = True
    Forms!frmDuties!sfrmRuns!sfrmNotes.Form.AllowAdditions = True
End Sub

And for the Edit command:
Code:
Private Sub CmdEdit_Click()
    Me.Form.AllowEdits = True
    Me.DutyDate.SetFocus
    Me.CmdEdit.Visible = False
    Me.sfrmRuns.Form.AllowEdits = True
    Me.sfrmRuns!sfrmNotes.Form.AllowEdits = True
End Sub

When I try to Add a record I get the below error:
Capture1.JPG

The error is on 'Forms!frmDuties!sfrmRuns!sfrmNotes.Form.AllowAdditions = True'

The error is similar for also the Edit command.

Thanks
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    98.9 KB · Views: 6
You may be missing another Form in that syntax. For example,
Forms!frmDuties!sfrmRuns.Form!sfrmNotes.Form.AllowAdditions
 
@theDBguy Thanks for the reply.
I have tried your suggestion but I am still getting the same error
Capture.JPG
 

Users who are viewing this thread

Back
Top Bottom