What you do is define a constant that represents the default date
field value.
Const DEFAULT_DATE_FIELD As String = "__/__/____"
When the form loads, make the textbox look like a date should be
entered:
Private Sub UserForm_Initialize()
' assume textbox name is 'TodaysDate'
Me.TodaysDate.Value = DEFAULT_DATE_FIELD
End Sub
Then use the Enter, Exit and AfterUpdate events to make the end user
believe it's a date field.
Private Sub TodaysDate_Enter()
On Error GoTo ErrorHandler
With Me.TodaysDate
If .Value = DEFAULT_DATE_FIELD Then
.Value = ""
End If
End With
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Private Sub TodaysDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo ErrorHandler
With Me.TodaysDate
If Len(.Value) = 0 Then
.Value = DEFAULT_DATE_FIELD
End If
End With
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Private Sub TodaysDate_AfterUpdate()
On Error GoTo ErrorHandler
' format phone number
With Me.TodaysDate
If Len(.Value) = 8 Then
.Value = Format(.Value, "##/##/####")
'.BackColor = RGB(255, 255, 255)
'Application.StatusBar = False
Else
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
' uncomment this line (and the backcolor line above) if you want
to visually indicate a data entry error
'.BackColor = RGB(255, 0, 0)
' uncomment this line if you want a messagebox indicator,
' although I don't recommend interrupting the user
'MsgBox ("Phone number must be ten digits: ##########")
' uncomment this line (and the statusbar line above) if you want
to use the Status bar to display error msg
'Application.StatusBar = "Phone number must be ten digits:
##########"
End If
End With
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
On Oct 23, 5:05*pm, TotallyConfused
wrote:
Your right it is not viewable. *It says it can't be found. *Is there any
other way I can obtain? *Thank you.
"JP" wrote:
You can't, but you can fake it somewhat. Here's one approach:
http://www.codeforexcelandoutlook.co...textboxes-like...
Technically it's not published yet, but you should still be able to
view it. But you should still follow Joel's advice and use the IsDate
function to verify that whatever is entered into a textbox is a valid
date.