Run-time error '2185' for Dynamically search multiple fields

stewegg

Registered User.
Local time
Today, 11:53
Joined
Mar 4, 2011
Messages
10
[Solved] Run-time error '2185' for Dynamically search multiple fields

Hi all,

I am trying to adpot this Dynamically search multiple fields into my db from John Big Booty at
w w w.a c c e s s-p r o g r a m m e r s.co.uk/forums/showthread.php?t=188663

Every thing works great except it gives me run-time error when there's no resault from the search.

The error shows:

Run-Tim error '2185':
you can't reference a property or method for a control unless the control has the focus.


Can anyone help me solve this problem?


Thank you very much.
 
Last edited:
Typically this happens when you use the .Text property of a control instead of the default .Value property.
 
Can you post a copy of the amended code you are using, or better still a copy of your DB.
 
Hi John Big Booty,

I am having trouble uploading my db.
It shows "Your submission could not be processed because a security token was missing".

However, this is what it looks like.....
Code:
Private Sub txtFind_Change()
    
'Create a string (text) variable
    Dim vSearchString As String
    
    Me.txtFind.SetFocus

'Populate the string variable with the text entered in the Text Box SearchFor
    vSearchString = txtFind.Text

'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll
    txtSerch.Value = vSearchString

'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
    Me.Meter_Inventory_No.Requery


'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
    If Len(Me.txtSerch) <> 0 And InStr(Len(txtSerch), txtSerch, " ", vbTextCompare) Then
        Exit Sub
    End If

'Set the focus on the first item in the list box
    'Me.Meter_Inventory_No = Me.Meter_Inventory_No.ItemData(1)
    Me.Meter_Inventory_No.SetFocus

'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box
    DoCmd.Requery

'Returns the cursor to the the end of the text in Text Box SearchFor
    Me.txtFind.SetFocus

    If Not IsNull(Len(Me.txtFind)) Then
        Me.txtFind.SelStart = Len(Me.txtFind)
    End If

End Sub


I have followed every steps of yours.
But, instead of list boxes I have used multiple text boxes due to the formate of my form.


Hop this is enough information for you to help me out.
 

Attachments

  • db.jpg
    db.jpg
    93 KB · Views: 230
Typically this happens when you use the .Text property of a control instead of the default .Value property.



Thank you for your reply.
But I thought this dynamic search is fine with text.
 
The code is specifically designed to work with a listbox, you are taking your project into areas unknown, into which I am not prepared to follow :eek:
 
What line throws the error?
 
The code is specifically designed to work with a listbox, you are taking your project into areas unknown, into which I am not prepared to follow :eek:


OK.

Thank you very much John Big Booty for designing the Dynamically search multiple fields.
 
That shouldn't throw the error, since you set focus right above that. Can you post the db?
 
That shouldn't throw the error, since you set focus right above that. Can you post the db?


Hi pbaldy,


I have tried to upload the file.
However, it shows "Your submission could not be processed because a security token was missing".

Do you know how I can solve this?



Thank you very much.
 
Not sure, but see if this helps:



I think it's because of the size of my file......
Let me try it again......

Hope this works....


Thank you very much


PS. I have deleted a lot of information due to the size issue...hope you can still understand it.......
 

Attachments

I'm not getting any errors on the meters_list search. It appears to be working as I would expect.
 
I'm not getting any errors on the meters_list search. It appears to be working as I would expect.


Hi pbaldy,

The error only occur when there is no matching result.
For example, if you try to search "99", the error would come up.



Thank you very much.
 
You can kludge around it with something like this right after the requery:

Code:
  If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "no records"
    Me.txtFind.Undo
    Me.txtFind.SetFocus
    Exit Sub
  End If
 
You can kludge around it with something like this right after the requery:

Code:
  If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "no records"
    Me.txtFind.Undo
    Me.txtFind.SetFocus
    Exit Sub
  End If


Hi pbaldy,


Thank you for your help.
This does solve the problem.
However, another problem came up.


After the if statement kicks in and exit the sub, the form doesn't reset or go back to the previous search result with the Me.txtFind.Undo function.

For example, after the implementation of the if statement, when you type "99", the "no records" msgbox pops up and nothing happens after that.
If I try to delete "99" another error message would come up.

How can I fix this problem?


Thank you very very much.
 
Problem Solved!

Code:
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "No Record Found"
        Me.txtSerch = ""
        Me.txtFind = ""
        DoCmd.Requery
        Me.txtFind.SetFocus
        Exit Sub
    End If


Thank you very much, pbaldy.
 

Users who are viewing this thread

Back
Top Bottom