473,503 Members | 10,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date comparison not functioning

82 New Member
hello there, my project is done...just noticed that my dates are not comparing properly ... it's working only if the year of returned date is less than the year of takeout date ... help me pleaaaasee =)

note: i divided the dates into 3 parts
e.g.:
takeoutday, takeoutmonth and takeoutyear
returnedday, returnedmonth and returnedyear

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtReturnedYear_AfterUpdate()
  2. Dim tDate As String
  3. Dim rDate As String
  4.  
  5. tDate = Format(Me.cmbTakeOutDay & "/" & Me.cmbTakeOutMonth & "/" & Me.txtTakeOutYear, "dd/mm/yyyy")
  6. rDate = Format(Me.cmbReturnedDay & "/" & Me.cmbReturnedMonth & "/" & Me.txtReturnedYear, "dd/mm/yyyy")
  7.  
  8. If CDate(rDate) < CDate(tDate) Then
  9.     MsgBox "Please change return date!"
  10.     Me.cmbReturnedDay.Value = ""
  11.     Me.cmbReturnedMonth.Value = ""
  12.     Me.txtReturnedYear.Value = ""
  13.  
  14.     Me.cmbReturnedDay.SetFocus
  15. Else
  16.     Me.txtReturnedYear.SetFocus
  17. End If
  18.  
  19. Me.cmdClearReturnedDates.Enabled = True
  20.  
  21. End Sub
Apr 12 '13 #1
10 5404
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Step through your code and check that the values assigned to tdate and rdate are the values you expect them to be.
Apr 12 '13 #2
deanvilar
82 New Member
sir Smiley, yes ... its actually same value ...
for example if takeoutdate = 2/3/2013 and returneddate = 1/5/2012 ... its ok... but if takeoutdate = 2/3/2013 and returneddate = 1/3/2013 it doesnt alarm me to change returned date =(
Apr 12 '13 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
If you make an example database containing just the form, the relevant controls, and that piece of code, I will be happy to spend some time looking it. You can upload it as a zipped file.
Apr 12 '13 #4
deanvilar
82 New Member
sure sir smiley, please find attached.
Attached Files
File Type: zip sample.zip (63.2 KB, 119 views)
Apr 12 '13 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Nice.
I should be able to look at it this evening.
Apr 12 '13 #6
deanvilar
82 New Member
thank you sir smiley in advance ....
Apr 12 '13 #7
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Okay I have taken a look at your form. I like the clean style gui you have setup, it seems professional.

I can see from your profile that you have a VB6 background, and when compared with what I see in form, I am guessing that you have run into a mistake alot of developers do when they first start using access. They make unbound forms and load/write date through the use of lots of code. Access comes with a built in system that will do all of that for you, if you use bound forms. The normal form wizard will help you do bound forms and they are so much easier to work with. Bound forms take care of recordset navigation, update, filters, sorts and much more. Furthermore the code you have is difficult to maintain since if you add a field to the table, you have a lot of code you now need to update. I strongly urge you to look into bound forms.


Back to the original problem. You are storing a date as a string, and manipulating it as a string, before converting it to date.
If you try typing this line of code into the above example at line 7:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format(CDate(rDate), "dd/mm/yyyy") & " || " & rDate
And look at the resulting output in the immediate pane, you get the following for the date january 6th 2013:
Expand|Select|Wrap|Line Numbers
  1. 01/06/2013 || 06/01/2013
Basically what happened is that the string you formatted as dd/mm/yyyy got read by access as mm/dd/yyyy, and after all how should Access know which date format you used? Access only sees a string, and tries to convert that to a date, the best it can. When you have a split date like that, with information stored in various fields, you should use the DateSerial function instead, to convert it to a date, since you can specify which part is the year, month and day.

Best of luck with your project.
Apr 14 '13 #8
deanvilar
82 New Member
thank you for the compliment Sir Smiley, yes I was a VB 6.0 programmer 8 years ago ... and got stuck in SAP which made me forget all those logical stuff in my mind ... anyways ... yep i tried using bound, its just i need more time to figure out how it really works in access, i cant manipulate them normally as what i really wanted that's why i used vba coding to do this ... a little bit of reminiscing and bump on my head i remembered some ways how to perform some operations ...

thanks for the suggestion sir smiley I will try using DateSerial function ... and ill let u know sir .. thank you again.
Apr 14 '13 #9
NeoPa
32,557 Recognized Expert Moderator MVP
DeanVilar:
note: i divided the dates into 3 parts
As soon as I read that I thought it would be the root of your problems. Have a look at Literal DateTimes and Their Delimiters (#) and see if it makes better sense to work with dates rather than strings. It really does make more sense.

I believe that's what Smiley is saying in a different way.
Apr 14 '13 #10
deanvilar
82 New Member
thank you sir NeoPa .... am going to check that link ...thanks
Apr 15 '13 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2965
by: Daniel Fisher | last post by:
Hi All! I'm fairly new to PhP and basicly trying to learn right now. Now I have a problem - I have a fairly large collection of movies which people keep borrowing from me. And then not returning....
8
1809
by: Lloyd Sheen | last post by:
Below is the output from command window. This shows values of variables and result of comparison. Make no sense except to dot.net. Any ideas?? ?pofile #11/11/2003 12:39:22 PM# ?pdtdbdate
3
6546
by: Karl Gibbon | last post by:
Hi There, I currently have a database in Access 2002 with several forms. I would like to restrict access to one form in perticular until November 1st every year. My current method (attempted...
6
8479
by: MarkAurit | last post by:
Im having difficulty coming up with a good algorithm to express the following comparison: "if <a given date> falls between the (current date - 5 days) and the (current date)" Obviously....
3
10210
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new...
7
2757
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
3
4037
by: noone | last post by:
Hi, I am designing an application which displays news topics until midnight on the DisplayUntil date and then they should drop out. Unfortunately, they seem to be dropping out at mid-day. I'm...
16
4430
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
2
2703
by: mikkaro04 | last post by:
hi.. i have a problem about date comparison in VB 6.0 and MS Access i want to compare dates from access to a date from DTpicker control in VB 6.0.. this is my code but it doesnt work coz i get a...
1
8904
by: leosuth | last post by:
Hi I've got the following function: public static List<Order> FilterByDateRange(List<Order> _list,string _sdate, string _edate) { if (_list.Count == 0) return null; ...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.