stop selection of past days on datepicker

Gr3g0ry

Registered User.
Local time
Today, 03:25
Joined
Oct 12, 2017
Messages
163
is there a way to stop my user from selecting past/previous days on a date picker ?
 
You can't prevent the past days appearing in the date picker
However if selected date is in the past you can block it

Something like this where DateControl is the name of your textbox:

If Me.DateControl <Date() Then
MsgBox "Please enter a date in the future", vbCritical, "Date error"
Me.DateControl = ""
End If
 
agree with this one, since Date Picker does not exposed any Events or Properties.
you can use three Events of the Control to disallow previous dates:


Code:
Dim bolKeyPressed As Boolean

Private Sub Text0_Change()
If Not bolKeyPressed Then
    If Me.Text0.Text <= Date Then
        MsgBox "Only Present and Future dates allowed."
        Me.Undo
    End If
End If
bolKeyPressed = False
End Sub

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
bolKeyPressed = True
End Sub

Private Sub Text0_KeyPress(KeyAscii As Integer)
bolKeyPressed = True
End Sub
 
thanks guys. all suggestions were tried and all worked.
 

Users who are viewing this thread

Back
Top Bottom