It should.
To use the code, you would open the subform in design view.
On the subform's property sheet, on the Events tab, find the event called
Before Insert
On the same as that event, click the button with 3 dots on in (it's on the
right)
Access will open the code window
Copy and paste this code into the code window
'start of code -------------
Option Compare Database
Option Explicit
Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Please enter the main form record first."
End If
End Sub
'end of code -------------------
Notes:
Now check the very first lines of code at the top of the code window.
If you see
Option Compare Database
more than once, delete the copies until there is only one occurrence of
Option Compare Database
Do the same for
Option Explicit
Now on the menu at top of the screen, choose
Debug, then compile.
Save and close the code window.
Save and close the form.
Test the form to see how the code works.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Hi Jeanette,
Will this also work if it is a tabbed subform? Sorry, I should have
[quoted text clipped - 32 lines]