Restrict Previous Date

P

Peter

Hi all,

Access 2007.I am using this code in the Before update event of a date field:

If Me.[Due] <MyDate Then
MsgBox "bla bla"
Cancel =True
End If

The Forms date field is formatted dd-ddd-mmm-yyyy so is the table field..but
the code does not fire...what am i doing wrong. I replaced Mydate with
Date()..but access refuses to save Date()..it saves only Date..

Thanks for help!
 
J

John W. Vinson

Hi all,

Access 2007.I am using this code in the Before update event of a date field:

If Me.[Due] <MyDate Then
MsgBox "bla bla"
Cancel =True
End If

The Forms date field is formatted dd-ddd-mmm-yyyy so is the table field..but
the code does not fire...what am i doing wrong. I replaced Mydate with
Date()..but access refuses to save Date()..it saves only Date..

Thanks for help!

Date (without the parentheses) is in fact correct in VBA code; it calls the
builtin Date function (unless you unwisely have a variable named Date!)

It's possible that whatever Due contains is being interpreted as text rather
than as a date/time value. Try

If CDate(Me!Due) < Date Then

to check for Due being earlier than midnight on the previous night. Use

If CDate(Me!Due) < Now Then

to check for the textbox containing a date/time value in the past (even one
second in the past!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top