473,804 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date compare isn't working like it should

105 New Member
Hi everyone!!

I have a continuous form that allows users to select a record and chnage the DATE that the record is assigned to another DATE within the same year. The button is called "Change plan Date Within 2008." The user can select a particular record, click that button and a new small form appears that displays the current Plan Date and a textbox for entering a new Plan Date.

Expand|Select|Wrap|Line Numbers
  1. 'If the New Plan Date is earlier than today's date, this is not allowed
  2. If DateDiff("d", Date, NDate) < 0 Then
  3.     MsgBox "You can not enter a Plan Date earlier than today's date."
  4.     Exit Sub
  5. End If
I want to make it to where when the user clicks on a record and then clicks that button and types in a new Plan Date and clicks OK, that it won't allow the user to type in a Plan Date that is EARLIER than the one already assigned to that record.

here's my code on that command, but so far it doesn't seem to be working like it should.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2. Dim NDate As String
  3. Dim oDate As String
  4.  
  5. 'Check to see if there is anything typed into the New Plan Date field, if not, close the form
  6. NewPlanDate.SetFocus
  7.  
  8. If NewPlanDate.Text = "" Then
  9.     DoCmd.Close acForm, "frmPlanChangeDate"
  10.     Exit Sub
  11. End If
  12.  
  13. oDate = OldPlanDate.value
  14. NDate = NewPlanDate.value
  15.  
  16. 'If the New Plan Date is earlier than today's date, this is not allowed
  17. If DateDiff("d", Date, NDate) < 0 Then
  18.     MsgBox "You can not enter a Plan Date earlier than today's date."
  19.     Exit Sub
  20. End If
  21.  
  22. 'If the user tries to change the year in this form, this is not allowed
  23. If Year(oDate) <> Year(NDate) Then
  24.     MsgBox "You can not change the year of the Plan Date here." & vbCrLf & "Please use the " & """" & "Move To" & """" & " buttons to change years."
  25.     DoCmd.Close acForm, "frmPlanChangeDate"
  26.     Exit Sub
  27. End If
  28.  
  29. 'Figure out the year and set the Plan Date appropriatly
  30.  
  31. Forms!frmPlan!frmPlanList.Controls("PlanDate").value = NDate
  32.  
  33. 'Close the form
  34. DoCmd.Close acForm, "frmPlanChangeDate"
  35.  
  36. End Sub
Mar 11 '08 #1
4 1939
jmarcrum
105 New Member
Nevermind I figured it out!

Expand|Select|Wrap|Line Numbers
  1. 'If the New Plan Date is earlier than today's date, this is not allowed
  2. If DateDiff("d", Date, NDate) < 0 Or DateDiff("m", Date, NDate) Then
  3.     MsgBox "You cannot enter a Plan Date earlier than today's date."
  4.     Exit Sub
  5. End If
Mar 11 '08 #2
jmarcrum
105 New Member
wait i may have spoke too soon.... it's still not workin...
Mar 11 '08 #3
jmarcrum
105 New Member
Nevermind I figured it out!

Expand|Select|Wrap|Line Numbers
  1. 'If the New Plan Date is earlier than today's date, this is not allowed
  2. If DateDiff("d", Date, NDate) < 0 Or DateDiff("m", Date, NDate) Then
  3.     MsgBox "You cannot enter a Plan Date earlier than today's date."
  4.     Exit Sub
  5. End If
OK I did figure it out!

Simple change

Expand|Select|Wrap|Line Numbers
  1. 'If the New Plan Date is earlier than the old date, this is not allowed
  2. If DateDiff("d", oDate, NDate) < 0 Then
  3.     MsgBox "You cannot enter a Plan Date earlier than the old date date."
  4.     Exit Sub
  5. End If
[/quote]
Mar 11 '08 #4
missinglinq
3,532 Recognized Expert Specialist
Actually, with dates, a simple

If Date1 < Date2 Then

works just fine!


Linq ;0)>
Mar 11 '08 #5

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

Similar topics

4
5132
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
4
5395
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
14
13271
by: Steve Wright | last post by:
I am trying to validate if an entry on a form is a date. I have adapted code I found here http://www.codingforums.com/archive/index.php/t-14325 as below but I can't seem the get the results that I am expecting. Can anyone help please TIA Steve PS I'm new to javascript
5
1175
by: JIM.H. | last post by:
Hello, Since I am learning C# now, I might have a simple question, I know my datarow dr keeps datatime and I need to compare it if it is current date, if not how many days ago? How should I compare date and find how many day difference? Thanks, Jim.
8
3658
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as text fields. Each date for example 10/31/03 or October 31st 2003 is stored as 10/31/A3 in the system. My reasoning for this is because they couldn't solve their Y2K problem or this is their solution to it. All dates prior to 2000 are stored...
9
3230
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database and not the file itself. To do this I will need to have a File class property for Create time and date that will let me "set" the Create time and date of the file to my own chooseing. The VB file class does not appear to have the ability
4
3765
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
12
29482
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
20
14271
by: keri | last post by:
Hi, I am creating a table where I want to use the date as the primary key - and to automatically create a record for each working date (eg Mon to Fri) until 30 June 2007. Is this possible? I do not want my user to have to create a record for each date. Thanks,
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.