• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Validate textbox control date with variable date

How validate textbox control date with variable date in VBA (ACCESS)
0
egovernment
Asked:
egovernment
2 Solutions
 
plummetCommented:
Hi

Can you explain exactly what you want to know? Do you want to validate a date variable or are you talking about a variable date?

0
 
egovernmentAuthor Commented:
For example I have an TextBox can only accept date format as yyyy -mm -dd so how I can validate the date value in text box with date stored in variable with type Date
0
 
GrahamSkanRetiredCommented:
You can validate it like this
Sub TestVD()
    MsgBox ValidateDate("2011 -10 -08")
    MsgBox ValidateDate("2011 -10 -32")
End Sub
Function ValidateDate(strText As String) As Boolean
    'yyyy -mm -dd
    ValidateDate = IsDate(Replace(strText, " -", "/"))
End Function

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
plummetCommented:
OK, you can compare dates just using the = , for example

if txtDate = cdate("2011-10-08") then print "Dates Match"

or possibly, to make sure there is a date in the text box (I have called it txtDate):

if isdate(txtDate) then
    if txtDate = cdate("2011-10-08") then print "Dates Match"
end if

or to see if the date entered in the textbox is earlier than today:

if isdate(txtDate) then
    if txtDate < now then print "Date is earlier than " & now
end if
0
 
plummetCommented:
If you do have spaces in the date for some reason then you can get rid of them by using the replace command like this:

if isdate(replace(txtDate, " ","")) then
  ...
0
 
egovernmentAuthor Commented:
I will check the all answers
0
 
mlmccCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now