Results 1 to 7 of 7
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    Date comparison problem.

    I want to compare two dates in Vba with Boolean operators. How to do it? One is coming from a text box control of my form. Other I put as a value. I tried-
    MyBoolControl = NZ(myTxtcontrol, Year(#1/1/1901#)) <> Year(#1/1/1901#)


    But it's not working. Also tried Format but in vain.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    just : year([date1]) <> year([date2])

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What you have should work, but "not working" means what?? Wrong result? Error message? Something else?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Micron View Post
    What you have should work, but "not working" means what?? Wrong result? Error message? Something else?
    It works on it's own, but when I have added multiple criteria for multiple controls it wont change MyBoolControl value accordingly. I guess I have to check each of them individually.

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Sorry Guys....
    I think I have found out the problem.
    There was a criteria where I had put the following code
    Code:
    Nz(Me.CNF_Bill, (-1)) > (-1)
    Somehow it changed my CNF_Bill field's value from 0 to -1. I used -1 to allow for 0 value bill (ie. for which we don't have to pay the bill at all). Now it seems to be working fine.
    Sorry again to have bothered you guys. Bug fixing appears to be a really rigorous task!!

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,559
    Quote Originally Posted by bubai View Post
    Sorry Guys....
    I think I have found out the problem.
    There was a criteria where I had put the following code
    Code:
    Nz(Me.CNF_Bill, (-1)) > (-1)
    Somehow it changed my CNF_Bill field's value from 0 to -1. I used -1 to allow for 0 value bill (ie. for which we don't have to pay the bill at all). Now it seems to be working fine.
    Sorry again to have bothered you guys. Bug fixing appears to be a really rigorous task!!
    What do you mean somehow?
    The value in that control would have been Null for that to happen, not 0?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Welshgasman View Post
    What do you mean somehow?
    The value in that control would have been Null for that to happen, not 0?
    I'm not sure at what stage of my coding and testing it has changed, but my purpose was to allow for rowlock using -1 as well as to allow for 0 so that I can keep track for CNF bills which I won't have to pay.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sum IIF date comparison issue
    By sergi117 in forum Access
    Replies: 3
    Last Post: 10-05-2018, 11:30 AM
  2. problem with date comparison when querying in vba
    By charis89 in forum Programming
    Replies: 8
    Last Post: 08-20-2015, 04:48 PM
  3. RC Notation and Date Comparison
    By mkc80 in forum Access
    Replies: 2
    Last Post: 10-10-2012, 06:22 PM
  4. VBA problem with IF comparison. HELP.
    By spkoest in forum Programming
    Replies: 6
    Last Post: 05-04-2011, 03:29 AM
  5. Short date comparison
    By andy101 in forum Programming
    Replies: 2
    Last Post: 03-17-2011, 04:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums