how to check textbox to see if date expired

bitsbb01

Registered User.
Local time
Today, 17:17
Joined
Apr 2, 2013
Messages
34
Hi everyone, well so far so good.. and now i've got a stupid problem that i just cannot seem to get to work...

basicly i want to check Textbox text528 and if the date in there has expired (anything older than today), then it'll notify me.. however weird thing is.. its notifying on dates still 10days to go, and not even notifying of other dates that have expired..

Code:
Dim EndDate As Date
   EndDate = Text538.Value
If EndDate < Date Then
MsgBox "The Service Plan Has Expired, Please Update ASAP", vbCritical, "SP Has Expired"
Else
End If
 
G'd evening!
First of, you don't need to create a variable for your textbox, second you don't need the value method, third to work with dates you should use vba.datediff, vba.dateadd, vba.dateserial etc.
In your case you accomplish that in several ways. Here is an easy way:

DateDiff
DateDiff ( interval, date1, date2, [firstdayofweek], [firstweekofyear])

PHP:
If VBA.DateDiff("d", vba.Cdate(Me.txtDate), VBA.Now) >= 1 Then
    Debug.Print "Date older"
 Else
    Debug.Print "Current"
 End If
G'd luck
 
G'd evening!
First of, you don't need to create a variable for your textbox, second you don't need the value method, third to work with dates you should use vba.datediff, vba.dateadd, vba.dateserial etc.
In your case you accomplish that in several ways. Here is an easy way:

DateDiff
DateDiff ( interval, date1, date2, [firstdayofweek], [firstweekofyear])

PHP:
If VBA.DateDiff("d", vba.Cdate(Me.txtDate), VBA.Now) >= 1 Then
    Debug.Print "Date older"
 Else
    Debug.Print "Current"
 End If
G'd luck
Don't use NOW unless there is a time element. That can cause unintended consequences. Use DATE instead.
 
Thanks for point that out! As a matter of fact i use to use vba.now instead of vba.date in my answers. The reason is that unless the question explicitly says that the time part is not required.
From now on i'll keep that in mind.
Cheers!
 
Thanks for point that out! As a matter of fact i use to use vba.now instead of vba.date in my answers. The reason is that unless the question explicitly says that the time part is not required.
From now on i'll keep that in mind.
Cheers!

In this case it wouldn't matter so much. But if you were using a BETWEEN statement, it can make a huge difference due to the comparison of the times included.
 
Thanks, didnt relize it'd be done that way, as was always using the other way, and have used it like that in Excel VBA...

And yes i did use the VBA.Date as thats better for me in long run..
 

Users who are viewing this thread

Back
Top Bottom