Prevent filling out sub folder

lasse.staalung

New member
Local time
Today, 15:06
Joined
Aug 16, 2017
Messages
5
I am trying to prevent users to make new records in a sub form, when the main form has no record. Normally we create a new record, when a user pick them selves with a combo box.
But several time, they start filling out the sub form, without making the record in the main form.
How can I prevent this from happening?.
Thank you:)
 
Only display or enable the sub form if you have a parent record, something like this in the OnCurrent event;
Code:
If Me.NewRecord Then Me.YourSubFormContainer.Enabled = False
 
Thank you, it led me on the right track.

I used this vba code in my sub form "On Current" event, and it worked, so the sub form is locked if there is no record in the main form, and unlocked when there is a record in the main form.


Code:
Private Sub Form_Current()
If IsNull([Forms]![MainForm]!MainRecord_ID) Then
With [Forms]![MainForm]!SubForm.Enabled = False
End With
Else
With [Forms]![MainForm]!SubForm.Enabled = True
End With
End If
End Sub
 
Good solution, you could simplify it quite a lot by using the Boolean nature of your IsNull ;

Code:
Private Sub Form_Current()

    [Forms]![MainForm]!SubForm.Enabled =  Not IsNull([Forms]![MainForm]!MainRecord_ID) 

End Sub
 

Users who are viewing this thread

Back
Top Bottom