Hi all,
I have a form, Form 1 with primary key PK_ID
I have a second form, Form 2 with foreign key FK_ID
I link through to Form 2 using the field PK_ID.
It is also possible to open Form 2 from Form 1 filtered by PK_ID again in add mode which allows the user to add a new record in Form 2 that automatically links to the record from Form 1.
What I'd like is an error message which traps the user on Form 1 if there are no related records in Form 2.
This code in the OnOpen event of Form 2 works perfectly for that method, however, I'd like the trap NOT to work if the user wants to ADD a new record.
I tried simply adding the If Not Me.NewRecord part to the code:
But it still doesn't work.
Any ideas?
Thanks for any help,
Leigh
I have a form, Form 1 with primary key PK_ID
I have a second form, Form 2 with foreign key FK_ID
I link through to Form 2 using the field PK_ID.
It is also possible to open Form 2 from Form 1 filtered by PK_ID again in add mode which allows the user to add a new record in Form 2 that automatically links to the record from Form 1.
What I'd like is an error message which traps the user on Form 1 if there are no related records in Form 2.
Code:
Private Sub Form_Open(Cancel As Integer) On Error GoTo Err_Form_Open If Me.RecordsetClone.RecordCount = 0 Then Cancel = True MsgBox "Please add a new Sub-Argument first before linking" End If Exit_Form_Open: Exit Sub Err_Form_Open: MsgBox Err.Description, vbCritical & vbOKOnly, _ "Error Number " & Err.Number & " Occurred" Resume Exit_Form_Open
I tried simply adding the If Not Me.NewRecord part to the code:
Code:
Private Sub Form_Open(Cancel As Integer) On Error GoTo Err_Form_Open If Not Me.NewRecord Then If Me.RecordsetClone.RecordCount = 0 Then Cancel = True MsgBox "Please add a new Sub-Argument first before linking" End If End If Exit_Form_Open: Exit Sub Err_Form_Open: MsgBox Err.Description, vbCritical & vbOKOnly, _ "Error Number " & Err.Number & " Occurred" Resume Exit_Form_Open End Sub
Any ideas?
Thanks for any help,
Leigh
Comment