• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Help with Subform validation (1 Viewer)

agma

New member
Local time
Today, 03:18
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

error reading drive A:
Local time
Today, 16:18
Joined
May 7, 2009
Messages
10,544
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: 6

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:18
Joined
Feb 19, 2002
Messages
29,724
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