Block a date entry

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Block a date entry

Post by KarenYT »

I have 2 date-fields : ReportDate and ShipDate
On the same record (Form), ReportDate is entered first, and then the ShipDate.
If the ShipDate is entered greater than the ReportDate, I want a warning msg pops up and block the entry, i.e. the ShipDate should always be lower than the ReportDate.

Please help.
thanks
Karen

User avatar
HansV
Administrator
Posts: 78410
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Block a date entry

Post by HansV »

Create a Before Update event procedure for the ShipDate text box:

Code: Select all

Private Sub ShipDate_BeforeUpdate(Cancel As Integer)
    If Not IsNull(Me.ReportDate) And Not IsNull(Me.ShipDate) Then
        If Me.ShipDate > Me.ReportDate Then
            MsgBox "Ship Date cannot be later than Report Date!", vbExclamation
            Cancel = True
        End If
    End If
End Sub
Best wishes,
Hans

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Re: Block a date entry

Post by KarenYT »

Thanks very much for the prompt response!
Works perfect!
Karen