well im a programmer, foremost, so i do everything with
code
(well almost)
the easy solution i think would be to use two textboxes
instead of one.
failing that, here's what I would do.
first, i wouldn't use an input mask, since they tend to
hide the actual value of the textbox.
well, it sounds like you are not allowing the month to be
changed in any way, so i really dont get why would want
the month to be included in the text box, you should write
it in a label to the side.
to do what you said i would put code into the LostFocus
event that takes the text, appends '/' & Year to try to
make it a valid date, and see if it becomes one. if not,
what they entered isn't valid. then i would check to see
if the month was the one i wanted. you can use a date
variable to store the initial date, (including year) and
put Format(d, "mm/dd") as the value of the control. here's
some code to make it more clear:
(other people here might have a better way using
validation rules, etc... but this is how i would do it)
unfortunately using LostFocus, you can't force the user to
remain at the control, so instead i make it erase the
user's entry if it was invalid. this may not be desirable,
in which case you may want to try something else. like i
said, this is how i would do it:
Private d As Date
Private sub Form_Load()
d = GetInitialDate() 'however you get your initial
value; not necessarily a function
DateBox.Value = Format(d, "mm/dd")
End Sub
Private Sub DateBox_LostFocus()
Dim s as string
s = DateBox.Value & "/" & Year
if not isdate(s) then
DateBox.Value = Format(d, "mm/dd")
'MsgBox optional
elseif Month(CDate(s)) <> MyMonth then
DateBox.Value = Format(d, "mm/dd")
'MsgBox optional
else
d = CDate(DateBox.Value)
DateBox.Value = Format(d, "mm/dd")
end if
End Sub