Problem with search-function (.SelStart - Run-time error 2185) (1 Viewer)

johndoomed

VBA idiot
Local time
Today, 12:09
Joined
Nov 4, 2004
Messages
174
Hi all!

I have some problems with a search function, or more precise the error-handling of the function.

I’ve added an unbounded textbox (Called search) in the toptext of a continuous form. The form is based on a query which is connected to the unbounded textbox (search).

I’ve written a basic vb function with is activated by the textbox (on change).

Code:
Private Sub search_Change()

    Me.Requery
    
        With Me!search
        Dim toSearch As String
        .SetFocus
        .SelStart = 300
        End With
    
End Sub

This works well, until there are no more posts to show. Then I get:

Run-time error ‘2185’ – You can't reference a property or method for a control unless the control has the focus

The cause is the .SelStart = 300. Without that line, the Run-time error will not occur. But, the line has to stay..

I’ve tried all the If’s and else’s I know, but could not find a fix. Any ideas?
 

johndoomed

VBA idiot
Local time
Today, 12:09
Joined
Nov 4, 2004
Messages
174
Just to work around this problem, how do I make a "if (there-is-no-records) then"?
 

Users who are viewing this thread

Top Bottom