Help with Subform validation (1 Viewer)

agma

New member
Local time
Today, 14:21
Joined
Oct 18, 2020
Messages
1
I have this access database-sample. I would like to be able to validate the violation input. If the violation is before the car sold date, it is okay to input. Otherwise, I will get an error message trying to input this in the form.

For example, Junker Camaro is sold on 3/18/2000. In Violation tab, I would be able to input any violation less than that sale date.

Any help is greatly appreciate.

Thank you..
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:21
Joined
May 7, 2009
Messages
19,169
your Tables should have Autonumber fields (ID).
create a Violation table (tblViolation) with fields:

CarID (long, FK to Car table)
ViolationDate (Date)
Violantion (short text)

add code to the form's beforeupdate event to check if the car's violationdate > solddate.
see this sample.
 

Attachments

  • violation.zip
    30.3 KB · Views: 142

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:21
Joined
Feb 19, 2002
Messages
42,973
Use the Form's BeforeUpdate event for validation. If the soldDate is on the parent form and your violations are being entered on a subform, then it will be something like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsDate(Me.Parent!SoldDate) Then
        If Me.ViolationDate > Me.Parent!SoldDate Then
            Cancel = True
            Msgbox "Violation Date may not be > SoldDate.", vbOKOnly
            Me.ViolationDate.SetFocus
            Exit Sub
        End If
    End If
End Sub
 

Users who are viewing this thread

Top Bottom