Full Version: Code For A Date between Date Ranges
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
saleeyoung
I have a form that can have up to ten different date fields. Date 2 is predicated on Date 1 and Date 3 on Date 2, etc. I need to write a code that will compare the current date within the different date ranges and then put a certain value in another field accordingly. Otherwords, if todays date falls between Date 2 and Date 3 then field X has a certain value or if the current date falls between date 3 and date 4 then field X has a different value. Obviously I can't get any code I tried to write to work. I've tried The < and > signs and also Between / And, but I'm totally lost. Also, since this has to be calculated everytime the form is opened and might be different for each record- I'm not sure just what event to put the code in. I've tried On Open, On Current-basically almost every event. Of course, if my code doesn't work - no matter where I put it, it won't work. Any help would be greatly appreciated. Even if it is just pointing me in the right direction. Thank you.
SerranoG
CODE
Select Case Date()
    Case Me.txtDate1 To Me.txtDate2
        'Code here
    Case DateAdd("d", 1, Me.txtDate2) To Me.txtDate3
        'Code here
    :
    more cases here, as many as needed...
    :
    Case Else
        'Code here
End Select
This assumes, of course, that all the date fields are entered. If not, you'll have null values that will have to be dealth with.
saleeyoung
Thank you very much.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.