Like you can read in this topic I made a filtering form that filters input data instantly. This all works great except for one problem.
I have a text box where a user can type a product number. The code for this is:
Code:
Private Sub txtProductNumber_KeyUp(KeyCode As Integer, Shift As Integer)
If Not IsNull(Me.Form.txtProductNumber) Then
Me.Form.Requery
Me.txtProductNumber.SetFocus
*****Me.txtProductNumber.SelStart = Len(Me.txtProductNumber)
Me.txtProductNumber.SelLength = 0
End If
End Sub
This VBA works great untill the user inputs a product number that doesn't exist in the database, because then I get the error (debugs on line the line with *):
Code:
Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.
But I just set the focus right before defining SelStart? I have a feeling that the form takes away the focus again, but how?