By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,479 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,479 IT Pros & Developers. It's quick & easy.

Validating Date of Non-Date Data Type

P: 97
Hi,

I need to compare a date (on a form )entered by a user with today's date and a date should not be greater than today. The problem, however, the data type for the date is string, not date date type. Is there anyway that I can test the user-entered-date against today's date? Thanks!
Oct 11 '07 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
You can use the CDate() function
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextDate_AfterUpdate()
  2. If CDate(Me.YourTextDate) > Date Then
  3.   MsgBox "Date must be  " & Date & "  or earlier!"
  4. End If
  5. End Sub
  6.  
Of course, one has to ask why you don't simply change the datatype to Date/Time?

Linq ;0)>
Oct 11 '07 #2

P: 97
You can use the CDate() function
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextDate_AfterUpdate()
  2. If CDate(Me.YourTextDate) > Date Then
  3.   MsgBox "Date must be  " & Date & "  or earlier!"
  4. End If
  5. End Sub
  6.  
Of course, one has to ask why you don't simply change the datatype to Date/Time?

Linq ;0)>

Thank you so much!
The data types of my db are given to me by my boss.
Oct 11 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Shows how much he knows! You have my sympathy!

Linq ;0)>
Oct 12 '07 #4

P: 97
Shows how much he knows! You have my sympathy!

Linq ;0)>
Hi, Linq!

I think that he tries to avoid any other conflicts by having string date type.

Anyway,
it works fine until it gets deleted and left blank. Then I get an error warning, "Invalid use of Null." Any help on this. I appreciate!
Oct 12 '07 #5

Post your reply

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