Answered by:
Stop Error Appearing

Question
-
I have a drop down list which is a number of pre-defined dates in it. If the user accidently types a letter in the box the whole code stops with a run-time error 13, Type Mismatch dialogue box. How can I get the code to stop erroring if the user types something by mistake. The code currently driving that box is;
Private Sub src_txt_1p_cont_start_Change()
TempDate = DateValue(src_txt_1p_cont_start.Value)
TempYear = Year(TempDate)
TempMonth = Month(TempDate)
EndDate = DateValue("1/" & TempMonth & "/" & TempYear + 1) - 1
src_txt_1p_cont_end.Value = Format(EndDate, "d mmmm yyyy")
End SubThanks in advance
Toni
Toni Chaffin aka Talisa
Monday, January 28, 2013 10:29 AM
Answers
-
Try this:
Private Sub src_txt_1p_cont_start_Change() If IsDate(src_txt_1p_cont_start.Value) Then TempDate = DateValue(src_txt_1p_cont_start.Value) TempYear = Year(TempDate) TempMonth = Month(TempDate) EndDate = DateValue("1/" & TempMonth & "/" & TempYear + 1) - 1 src_txt_1p_cont_end.Value = Format(EndDate, "d mmmm yyyy") Else Beep ' Not a valid date End If End Sub
Regards, Hans Vogelaar
- Marked as answer by TSRC Monday, January 28, 2013 11:49 AM
Monday, January 28, 2013 11:00 AM -
In addition, I only want them to be able to select a value in the list.
You can change the Style property of the combo box to 2 - fmStyleDropdownListRegards, Hans Vogelaar
- Marked as answer by TSRC Monday, January 28, 2013 11:50 AM
Monday, January 28, 2013 11:27 AM
All replies
-
In addition, I only want them to be able to select a value in the list.
Thanks
Toni Chaffin aka Talisa
Monday, January 28, 2013 11:00 AM -
Try this:
Private Sub src_txt_1p_cont_start_Change() If IsDate(src_txt_1p_cont_start.Value) Then TempDate = DateValue(src_txt_1p_cont_start.Value) TempYear = Year(TempDate) TempMonth = Month(TempDate) EndDate = DateValue("1/" & TempMonth & "/" & TempYear + 1) - 1 src_txt_1p_cont_end.Value = Format(EndDate, "d mmmm yyyy") Else Beep ' Not a valid date End If End Sub
Regards, Hans Vogelaar
- Marked as answer by TSRC Monday, January 28, 2013 11:49 AM
Monday, January 28, 2013 11:00 AM -
In addition, I only want them to be able to select a value in the list.
You can change the Style property of the combo box to 2 - fmStyleDropdownListRegards, Hans Vogelaar
- Marked as answer by TSRC Monday, January 28, 2013 11:50 AM
Monday, January 28, 2013 11:27 AM -
Thanks Hans as usual
Toni
Toni Chaffin aka Talisa
Monday, January 28, 2013 11:50 AM