MSAccess: How to automatically create a new parent form record when when data is first entered into a child form

22 views Asked by At

I need a parent form [FrmSubGrantsAgreements] to automatically create a new record when information entered first into the child form [FrmSubGAFndngSrcPrtnrs].

I tried to add code that would force the parent form [FrmSubGrantsAgreements] to create a new record when information is first entered into the child form [FrmSubGAFndngSrcPrtnrs]. I modified the code given in this thread: MS Access automatically fill id in main form when data is entered in subform. The explanation seemed pretty straightforward, but the original stackoverflow thread mentions adding a new field to the parent form’s table, which appeared to me to be the same field as my GrAgrID. I added the code to the On Dirty Event. But it's not working.

For the moment, I have added a note on the form instructing the user to make sure they have entered "unknown" into one of the short text fields in the parent form before entering info into the child form. Clunky, I know. But I need to move the project forward. Any ideas what I might be doing wrong? LMK if there is more information you need to consider this question. Respect.

Private Sub GRAgrNbr_Dirty(Cancel As Integer)
    With Me.FrmSubGrantsAgreements
        If IsNull(!GrAgrID) Then
            ' Change any field to create the parent record
            .Description = "Test"
            ' Save changes on the parent form.
            .Dirty = False
        End If
    End With
End Sub
0

There are 0 answers