I have an unbound form with a combobox which needs to be validated before the control is updated.
In the Before Update event I check that the value is valid and need to reset the value back to the previous value if not valid and then change focus to another control.
I thought that the following code would work but the selected value remains in the control and I cannot move the focus to another control.
Any ideas anyone?
In the Before Update event I check that the value is valid and need to reset the value back to the previous value if not valid and then change focus to another control.
I thought that the following code would work but the selected value remains in the control and I cannot move the focus to another control.
Any ideas anyone?
Code:
Private Sub cboYears_BeforeUpdate(Cancel As Integer)
Dim dteNewDate As Date
dteNewDate = DateSerial(Val(Me.cboYears), Month(Me.txtCalendarHeading), 1)
If Not fncIsDateInRange(fncFirstDayInMonth(dteCalStartDate), fncLastDayInMonth(dteCalEndDate), dteNewDate) Then
MsgBox "Date not in range"
Cancel = True
Me.cmdCancel.SetFocus
End If
End Sub