Solved Add and Edit VBA for form and relative subforms (1 Viewer)

E9-Tech

New member
Local time
Today, 00:38
Joined
Apr 28, 2021
Messages
26
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: 25
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
 
@theDBguy thanks for looking into it, I don;t seem to see how you adjusted the error? Am I missing something?
Thanks again
 
you can't have a datasheet subform that will host another sub-subform.
 

Users who are viewing this thread

Back
Top Bottom