MS Access 2016 - Add 2 separate criteria behind Before Update event

63 Views Asked by At

I have VBA code behind a form field to ensure that the parent record is created before the 'Discussed' field in the subform can be entered:

Private Sub Discussed_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Parent.ID) Then
   MsgBox "You cannot save this record without entering the issue details", vbOKOnly
   Cancel = True
   Exit Sub
End If
'...
End Sub

This works fine but I also want to make sure that the same discussion date is NOT added against the same Issue ID so I have found this:

If DCount("*", "Discussed", "[Issue_ID]= " & Me.[Issue_ID] & " and [Discussed]= #" & Format(Me.[Discussed], "dd/mm/yyyy") & "#") > 0 Then
    MsgBox "You entered a duplicate date. Please try again.", vbInformation, "Duplicate Date!"
    Cancel = True
    Me.Discussed.Undo
    '...
End If

Am not sure how to add this criterion into the same sub as one criterion seems to cancel out the other - any advice would be greatly appreciated

Adding in second criteria did not do anything

1

There are 1 best solutions below

3
Albert D. Kallal On

As I pointed out in your comments, it not really possible to move focus to the sub form without the parent form automatic saving the parent record. Not only is this a requirement for relational databases, it also why Access automatic executes a save for in the parent record when focus moves to the child form.

Thus, if you are somehow able to move to the child form, and enter data, then some details here are missing, since this in theory should not be possbile.