Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2005
    Posts
    49

    Unanswered: If time is less then 9, date = yesterday

    I need help with Access 2003....

    if ( hour(now) =< "9") {
    which = date() - 1
    }
    else {
    date(now)
    }


    How do I convert that into Access/VB code?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ..almost there, this should work.....
    if hour(now())<9 then
    <mydatevar>=now()-1
    else
    <mydatevar>=now()
    endif

    the downside with thsi is that you will be also assigning a time, so it might be better to clear the time element of the datevalue. - if the time is unimportant then it shouldn't matter what you store
    HTH

  3. #3
    Join Date
    Nov 2005
    Posts
    49
    The times important...so something like this would work?


    if hour(now())<9 then
    txtfile.ControlSource =now()-1
    else
    txtfile.ControlSource=now()
    endif

  4. #4
    Join Date
    Nov 2005
    Posts
    49
    I keep getting #Name? in the txtfile box.


    Basically the time is important to determine whether or not to show yesterdays date or todays.

    So if time > 10 (24 hour clock) then show todays date but if its less then 10 show yesterdays date (which is where the txtfile.ControlSource comes in)
    Last edited by jmweb; 01-03-06 at 05:07.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you are trying to assign the value form a date function to a controls source. Can't be done. either assign a value to the control - or assign a variable to the contorl source

    eg
    if hour(now())<9 then
    txtfile.value =now()-1
    else
    txtfile.value=now()
    endif
    That is based on the current system time, if you want to looka at exisiting records then

    if hour(<mydatecolumn>)<9 then
    txtfile.value =<mydatecolumn>-1
    else
    txtfile.value=<mydatecolumn>
    endif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •