To check that a value is in range, use the BeforeUpdate event of the
control, or of the form. Example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DateDiff("m", Me.[YourDateFieldNameHere], Date) > 6 Then
If MsgBox("More than 6 months ago?", vbYesNo+vbDefaultButton2) <>
vbYes Then
Cancel = True
End If
End If
End Sub
To prevent changes to records that are older than a certain date, use the
Current event procedure of the form to change the form's AllowEdits
property:
Private Sub Form_Current()
Dim bLock As boolean
If DateDiff("m", Me.[YourDateFieldNameHere], Date) > 6 Then
bLock = True
End If
Me.AllowEdits = Not bLock
Me.AllowDeletions = Not bLock
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Wesley said:
my database has a table where users enter data directly. is there away i
can make sure that they don't enter a date older than a certain point when
they enter a new record with out affecting data that is already in the
table? and can i lock older records to prevent changes?