Results 1 to 10 of 10
  1. #1
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250

    Runtime 2185 when updating wilcard search

    Hello,

    I'm trying to do "Search as you type" continuous form:

    Code:
    Private Sub txtCitySearch_Change()
        Me.Refresh
        
        Me.RecordSource = "SELECT CountryName, RegionName, CityName, ZIPCode " & _
                            "FROM dbo_vw_AddressDatabase " & _
                            "WHERE CountryName LIKE ""%" & txtCountrySearch & "%"" AND " & _
                            "RegionName LIKE ""%" & txtRegionSearch & "%"" AND " & _
                            "CityName LIKE ""%" & txtCitySearch & "%"" AND " & _
                            "ZIPCode LIKE ""%" & txtZIPSearch & "%"";"
        
        txtCitySearch.SetFocus
        txtCitySearch.SelStart = Nz(Len(txtCitySearch), 0)
        
    End Sub
    This works fine as long as it actually returns some rows. But once I type some non-existent search which doesn't return data, I get Runtime 2185 error.

    Would you by any chance have any ideas how I could fix it?



    Thanks a lot!

    Tomas

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What is the exact error message?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    if this is a query on an access table you need to use *, not % which is used with ADO and many rdbms's. access tables use DAO

    I would also say this will become a very slow process once you have a large dataset since you are bringing data over the internet every time you add or remove a character. Plus the use of the initial '%' or '*' prevents the use of indexing so access has to do a sequential search of the whole table. I don't include the initial * when building sql like this - but train the user to use it when required, or include a button the user can click to add the * for them.

    I would not bring any records through until the user has finished typing and then clicks a 'search' button to requery the form.

    Or if you need to do it this way wait until a meaningful number of characters have been typed (perhaps 3 or 4) before refreshing the recordsource.

  4. #4
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Hi,

    it's an SQL Server View.

    This is the error message:

    Click image for larger version. 

Name:	access1.PNG 
Views:	18 
Size:	7.0 KB 
ID:	47941

    This will never be more than a couple of hundreds records, so performance is no concern for me.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Add some error checking?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Please don't be lazy - provide the translation of the error

    Access VBA - Error '2185' - Can't reference a property unless the control has the focus



    you need to step through the code to find out which line is causing the problem - note the change event only fires when the control has the focus

    good luck

  7. #7
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    I don't see how googling a runtime number is more complicated than translating. My language is much more complicated than English and my translation would not necessarily reflect the real meaning of the runtime error message.

    This is the source view:
    Click image for larger version. 

Name:	view1.PNG 
Views:	18 
Size:	35.4 KB 
ID:	47942


    This is the code and the error line:
    Click image for larger version. 

Name:	code1.PNG 
Views:	19 
Size:	21.8 KB 
ID:	47943

    It's actually quite strange. I didn't have the .SetFocus there before, but then the error would trigger after every change.
    Now it works when there are records that match the search, but the error triggers when there is no record matching the search.

    I would appreaciate any insights Thanks.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I don't see how googling a runtime number is more complicated than translating.
    You are the one asking for help, the easier you make to for people to help you, the more likely you are to get help. We are all volunteers but want to make best use of our time, not waste time 'filling in the blanks'.

    here is a link to the change event
    https://docs.microsoft.com/en-us/off...textbox.change

    suspect you need to use the .text property for what you are trying to do

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Googling an error number does not always provide information sufficient to understand the error and as noted, is time consuming. Always provide the exact error message with translation as well as the line that triggers error.

    I tested SelStart when form does not have records and don't get error. However, did not test with Change event. I have never used it.

    Review http://allenbrowne.com/AppFindAsUType.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Thanks a lot everyone, I will try to provide better info in the future.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-10-2022, 07:10 PM
  2. Getting 2185 in VBA Code
    By emhill57 in forum Access
    Replies: 9
    Last Post: 10-09-2017, 06:19 PM
  3. Replies: 15
    Last Post: 05-12-2016, 02:27 PM
  4. Wilcard search using table
    By raytackettsells in forum Queries
    Replies: 6
    Last Post: 10-15-2013, 10:36 AM
  5. RunTime Error 3075, code for search button
    By jacie in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums