Results 1 to 5 of 5
  1. #1
    joesommers is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2024
    Posts
    2

    Form Will Not Display records after Error Handling/Requery

    Hello folks!

    I am bit of a novice to Access VBA, I know just enough to be dangerous...to my own progress! I have a continuous form, frmList_MC that employs search as you type feature. The code works great for its intended purpose, however once I type in a value that is not in the record source, a RTE 2185 gets thrown and a requery does not return the records, the form stays empty. Code as follows:

    Private Sub txtSearch_Change()
    On Error GoTo CleanFail

    Me.AllowAdditions = True

    Me.RecordSource = "SELECT * FROM qryList_MC " & _
    "WHERE " & _
    "[LF] LIKE ""*" & txtSearch.Text & "*"" OR " & _
    "[MCY] LIKE ""*" & txtSearch.Text & "*"" OR " & _
    "[LicensePlate] LIKE ""*" & txtSearch.Text & "*"""


    txtSearch.SetFocus
    txtSearch.SelStart = Len(txtSearch.Text)

    Me.AllowAdditions = False

    CleanExit:
    Exit Sub


    CleanFail:
    If Err.Number = 2185 Then
    MsgBox "Search criteria has no match."
    Err.Clear
    Resume CleanExit
    End If
    End Sub


    Private Sub cmdRefresh_Click()
    SetDefaults 'txtSearch = ""


    Me.Requery
    DoCmd.GoToControl "txtSearch"
    End Sub

    In order to test the requery I swapped it out for DoCmd.Close then OpenForm and thatt does not work either. However, clearing the text field and .setfocus works just fine. Scratching my pea brain here and would truly appreciate a bail out. I do not like wasting folks' time, so i hope I provided the correct/sufficient info! TIA!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps add the following line:
    Me.RecordSource = "SELECT * FROM qryList_MC "
    before the ilne:
    Resume CleanExit
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    joesommers is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2024
    Posts
    2
    Thank you so much, Mr. Fitz! Worked perfectly!

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by joesommers View Post
    Thank you so much, Mr. Fitz! Worked perfectly!
    You're welcome. Always happy to help, if I can
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    If later on, you wish to change your recordsource, you will need to amend the code as well as the search criteria.
    I would save the recordsource to a string variable and then the recordsource to that variable if you egt that error as Bob has advised.

    Just one less thing to change, especially if inexperienced.
    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

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

Similar Threads

  1. Field sometimes doesn't display after Requery.
    By Perfac in forum Programming
    Replies: 7
    Last Post: 04-04-2023, 05:36 PM
  2. Replies: 1
    Last Post: 09-13-2022, 03:44 AM
  3. Replies: 7
    Last Post: 09-09-2020, 07:22 PM
  4. AfterUpdate requery does not requery list box
    By ittechguy in forum Programming
    Replies: 5
    Last Post: 09-05-2017, 08:51 AM
  5. Replies: 5
    Last Post: 09-06-2015, 12:06 PM

Tags for this Thread

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