PauliusM
PauliusM

Reputation: 169

runtime error 2455 for textbox.selStart property

I am using this simple code to filter my report. Textbox Text123 is in the header of the report.

Private Sub Text123_KeyUp(KeyCode As Integer, Shift As Integer)
Dim str As String
str = Me.Text123.Text

If Me.Text123 = "" Then
    Me.Report.filter = ""
    Me.Report.FilterOn = False

 Else
    Me.Report.filter = "[ItemNo] Like '*" & Me.Text123.Text & "*'"
    Me.Report.FilterOn = True

End If
Me.Text123.SetFocus
Me.Text123.Text = str
Me.Text123.SelStart = Len(str)
End Sub

I am geting error on the line Me.Text123.SelStart = Len(str). error says "you entered an expression that has an invalid reference to the property selstart" What is the problem?

Upvotes: 1

Views: 584

Answers (3)

Tom Crocker
Tom Crocker

Reputation: 1

I believe the problem is because this is in a report not a form. My workaround is to make the report a subreport of a form, with the text box in the form. The following works for me:

Private Sub Text123_KeyUp(KeyCode As Integer, Shift As Integer)
    If Nz(Text123.Text, vbNullString) = vbNullString Then
        Me!rprtToFilter.Report.FilterOn = False
    Else
        Me!rprtToFilter.Report.Filter = "[ItemNo] like '*" & Text123.Text & "*'"
    End If
End Sub

Text boxes seem to behave differently on reports - they don't have a change event and if you move the focus elsewhere they seem to lose their text, though I can't find documentation about this.

Upvotes: 0

PaulFrancis
PaulFrancis

Reputation: 5809

I am unable to reproduce the problem ! However, the error seems illogical. I am a bit concerned what the ultimate motive of this code is. Try shuffling this around, see if that helps !

Private Sub Text123_KeyUp(KeyCode As Integer, Shift As Integer)
    Dim str As String
    str = Me.Text123

    If Len(Me.Text123 & vbNullString) = 0 Then
        Me.Report.Filter = ""
        Me.Report.FilterOn = False
     Else
        Me.Report.filter = "[ItemNo] Like '*" & Me.Text123.Text & "*'"
        Me.Report.FilterOn = True
    End If

    Me.Text123.SetFocus
    Me.Text123 = str
    Me.Text123.SelStart = Len(str)
End Sub

Upvotes: 0

Jens
Jens

Reputation: 879

Me.Text123.text should be Me.Text123.Value or just Me.Text123. What's even more so, that last line of code Me.Text123.Text = str has no use whatsoever here, so preferably you should omit it.

Upvotes: 0

Related Questions