Selasa, 16 Mei 2017

Re: [MS_AccessPros] Comparing 2 dates

 

Phucon-


What table is qryDate based on?  Is InputDate in the table a Date/Time data type?  It could be that you or on a machine that is non-US, so the default system date formatting is dd/mm/yyyy not mm/dd/yyyy.  That still doesn't explain why it thinks 1/3/2017 is greater than 1/8/2017 - on a non-US machine, those should be March 1 and August 1, respectively.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On May 16, 2017, at 8:49 PM, saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:





I have 2 combo boxes that contain a list of dates. One combo box is named "Date Start", the other is "Date End". And the date is in the format like this: mm/dd/yyyy. The row source of the 2 boxes is based on the same query as shown below:

 


SELECT DISTINCT InputDate FROM qryDate ORDER BY EntryDate;

 


I am using the 2 procedures below to compare the 2 dates after users selected the dates from the combo boxes, however sometimes it works correctly and sometimes it doesn't.  For example, 1/8/2017 was selected in the StartDate box  and 1/3/2017 was selected in the EndDate box or vice versa.  I expected the message box will pop up when the error occurs, it does right sometimes but not always.  Is 1/8/2017 greater than 1/3/2017, or  2/5/2017 less than 2/17/2017 ?

 


And here are my procedures for the 2 combo boxes:

 


Private Sub cboStartDate_AfterUpdate()

    If Me. cboStartDate.Value > Me.cboEndDate.Value Then

        MsgBox "Start Date cannot be greater than End Date."

    End If

End Sub

 


Private Sub cboEndDate_AfterUpdate()

    If Me.cboEndDate.Value < Me.cboStartDate.Value Then

        MsgBox "End Date cannot be less than Start Date."

    End If

End Sub

 


 


Phucon




__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar