Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • 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
 
GrahamSkanCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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