I am beginning to think what I want is not possible.
I have an unbound textbox that is used to input search criteria to find record in subform.
InputMask: 0000"A-"0000;0;_
DefaultValue: Year(Date())
Code for the textbox:
Code:
Private Sub tbxLabNum_BeforeUpdate(Cancel As Integer)With Me.ctrSampleList.Form.RecordsetClone
.FindFirst "LabNum='" & Me.tbxLABNUM & "'"
If .NoMatch = True Then
MsgBox Me.tbxLABNUM & " is not valid Lab Number", , "EntryError"
Me.tbxLABNUM.SelStart = 6
Cancel = True
Else
Me.ctrSampleList.Form.Bookmark = .Bookmark
End If
End With
End Sub
This all works but decided it would be even better if I could undo the user's bad input. As is, the invalid input is retained by the textbox and user can't leave the textbox without hitting ESC key or typing valid entry. I know I could use a combobox but users like just entering the last 4 characters, rarely (except at beginning of new year) do they need to search for prior year record by typing the prefix . I have tried:
1. The obvious - UNDO method, doesn't seem to do anything with unbound control
2. Sendkeys "{ESC}" but then the entire default value is selected
3. Setting the textbox value can't be done in BeforeUpdate
4. The SelStart method is totally ignored in AfterUpdate and cursor sits at beginning of the prefix and user has to cursor right or mouse click to the suffix or type the entire value
This is not a critical enhancement, just a 'would be nice', although users feel current behavior is tolerable.
So can I have my cake and eat it too?