compare date

kiko11

New member
Local time
Today, 06:45
Joined
Jul 12, 2005
Messages
9
Hello all
Ihave tblyear contain ( B_date and E_date )
in anoter form have feald ( invdate ) i wnat ( Invdate) is between B_date and E_date of the tblyear.
Thank u
 
Actually its not fully clear. It sounds like you want to validate the date entered by checking to see if it falls between the 2 dates. Does tblYear only have one record?
 
First Thank u ScottGem for replay me .
u r right , u understand what i want exact. my tblyear contan 2 fead not 1 , The 1st B_date , 2nd E_date
Thanks again
 
I understood it contained 2 fields but is it only 1 RECORD?
 
u mean one row ? or what u mean ?
 

Attachments

  • tbl.JPG
    tbl.JPG
    7.3 KB · Views: 115
Rows are a spreadsheet term. Database tables have records.

What you want to do is use the After Update event of the text box to veify the entry using code like:

IF Me!InvDate < DLookup("[B_Date]","tblYear") OR Me!invDate > DLookup("[E_Date]","tblYear") Then
MsgBox "Invoice date outside of range", vbOKOnly
Me!InvDate = Null
Me!InvDate.SetFocus
End If
 
You should use the BeforeUpdate event of the control in conjunction with Cancel=True to validate entries, not the AfterUpdate event
 
Thank u Sccotgem 4 ur code , and thanks 4 Rich . it is right in beforeupdate
and i modifi the code to that :

If Me!inv_date < DLookup("[B_Date]", "tbl_Year") Or Me!inv_date > DLookup("[E_Date]", "tbl_Year") Then
MsgBox "Invoice date outside of range", vbOKOnly
DoCmd.CancelEvent
SendKeys "{f2}", False

it is work good .
Ashraf
 
Also do away with the DoCmd.Cancel Event and replace it with
Cancel=True and do away with SendKeys
 
Also, to make youself clearer I'd advise that you use proper English - this isn't text messaging or a chatroom. There are others for whom English is not a first language and they may not be aware of abbreviations such as ur which can lead to confusion.

Also, the "oldies" can't keep up... ;)
 

Users who are viewing this thread

Back
Top Bottom