Help

J

John Vinson

It would help if I included the sub:

Sub CheckDate()
Dim strDate As String

strDate = InputBox("Enter string to display as a date.")
' Test variable.
If IsDate(strDate) Then
' If string is date, format and display in dialog.
MsgBox "The date is: " & Format(DateValue(strDate), "Long Date")
Else
MsgBox "The value you entered is not a date."
End If
End Sub

I would suggest that you copy and paste this code into a new Module.
Save the module with some name *DIFFERENT* than CheckDate - a module
and a sub cannot have the same name.

As written the code isn't going to be terribly useful - you could call
it from a Query but all it would do is pop up a message box no matter
what the user types. Could you explain what you *want* it to do?

John W. Vinson[MVP]
 
M

mk62

John Vinson said:
I would suggest that you copy and paste this code into a new Module.
Save the module with some name *DIFFERENT* than CheckDate - a module
and a sub cannot have the same name.

As written the code isn't going to be terribly useful - you could call
it from a Query but all it would do is pop up a message box no matter
what the user types. Could you explain what you *want* it to do?

John W. Vinson[MVP]
I would like it to only return text that would fit into a specific format.
(ie. short date, long Date, etc.)
 
J

John Vinson

I would like it to only return text that would fit into a specific format.
(ie. short date, long Date, etc.)

Ummm...

Why?

A Date/Time value is stored as a number. It's not stored with any
particular format. You can specify any format you wish for it, on a
form or report. What's the context? What are you trying to accomplish?

Just FWIW a function that would do what you describe - take a text
string and return a Short Date translation of it - might be

Public Function CleanDate(strIn As String) As String
If IsDate(strIn) Then
CleanDate = Format(CDate(strIn), "Short Date")
Else
CleanDate = "Not A Date: " & strIn
End If
End Function

This would take an input of "2-Dec-2041" and return "12/2/2041", an
input of "Fred" and return "Not a Date: Fred", and an input of
"2/30/2005" and return "Not a Date: 2/30/2005".

John W. Vinson[MVP]
 
Top