I have two similar forms based on similar data from two different tables. They are continuous forms with unbound text boxes in the header of the forms to align with the fields shown in form. When I type in the unbound text box it filters the form. The problem is this - on one form if I type something not in the list, I can back space in the unbound txtcontrol, on the other form, it gives me an error and says "You can't reference a property or method for a control unless it has the focus" I can't figure out the difference. Also the form I can backspace in the unbound control will let me edit the records in that form, the form that gives the error will not let me edit records. I can't figure out what I did to not allow the records to be edited, but I'm sure I did it when I created the form but as a newb i didn't document it.
All of the properties are the same for each form.
Here is the code for the form with control that works:
Here is the code for the form that gives the error:
All of the properties are the same for each form.
Here is the code for the form with control that works:
Code:
Private Sub txtDescFilter_Change()
Dim sText As String
Dim strFilter As String
On Error GoTo ErrHandler
sText = Me!txtDescFilter.Text
If sText <> "" Then
strFilter = "[Description] Like '*" & sText & "*'"
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.Filter = ""
Me.FilterOn = False
End If
With Me.txtDescFilter
.SetFocus
.Value = sText
.SelStart = Len(sText)
.SelLength = 0
End With
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
'MsgBox ("That text is not in the list")
'Me.Requery
End Sub
Here is the code for the form that gives the error:
Code:
Private Sub txtJobNameFilter_Change()
Dim sText As String
Dim strFilter As String
On Error GoTo ErrHandler
sText = Me!txtJobNameFilter.Text
If sText <> "" Then
strFilter = "[JobName] Like '*" & sText & "*'"
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.Filter = ""
Me.FilterOn = False
End If
With Me.txtJobNameFilter
.SetFocus
.Value = sText
.SelStart = Len(sText)
.SelLength = 0
End With
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
'MsgBox ("That text is not in the list")
'Me.Requery
End Sub