Results 1 to 5 of 5
  1. #1
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53

    FindRecord Crash if criteria not found

    Hello,

    I made a continuous form from a query with 2 comboBoxes to filter the query.

    in the query the code of each column is:
    Code:
    Like "*" & [Forms]![Part_List_form]![Stat_Box_Select] & "*"
    Code:
    Like "*" & [Forms]![Part_List_form]![Cat_Box_Select] & "*"
    for the combo boxes the code is:
    Code:
    Private Sub Cat_Box_Select_AfterUpdate()
    
    
        Me!Category.SetFocus
        If IsNull(Me!Cat_Box_Select.Value) Then
            Exit Sub
        
        Else:
        DoCmd.FindRecord (Me!Cat_Box_Select.Value)
        End If
        
        DoCmd.ShowAllRecords
    and

    Code:
    Private Sub Stat_Box_Select_AfterUpdate()
        
        Me!Status.SetFocus
        If IsNull(Me!Stat_Box_Select.Value) Then
            Exit Sub
        
        Else:
        
        DoCmd.FindRecord (Me!Stat_Box_Select.Value)
        End If
        
        DoCmd.ShowAllRecords
        
    End Sub
    It all works fine. I can use both combobox to filter or just 1 and leave the other blank and it still works.

    However when I use both and the criteria is not found, for example if a category doesn't have any records with that status, it will crash saying:


    Run-Time Error "2137"
    You can't use Find or replace now


    anyone have any ideas on how to fix this.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Based on your comment of it crashing when no record is found you could insert the following code to check if a record exists for the form's recordset.

    Dim rcd As Recordset
    Set rcd = Me.RecordsetClone
    If rcd.RecordCount <= 0 Then
    Exit Sub
    End If

  3. #3
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    Use the DCount or the DLookup function. It will count records if the provided criteria is matched. If so, proceed with next line of code, otherwise bail out.

  4. #4
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    Awesome that worked
    Thanks so much everyone
    on to the next mission

  5. #5
    mrojas is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2013
    Location
    Concord California
    Posts
    72
    If solved, please mark it so.

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

Similar Threads

  1. Access crash
    By Tjaaaa in forum Access
    Replies: 10
    Last Post: 03-07-2014, 05:41 PM
  2. can not use FindRecord with string
    By john60 in forum Programming
    Replies: 2
    Last Post: 08-10-2013, 08:25 AM
  3. Replies: 3
    Last Post: 01-31-2013, 07:20 PM
  4. Filter or FindRecord in Split Form
    By P5C768 in forum Forms
    Replies: 4
    Last Post: 03-20-2012, 12:16 PM
  5. Can you use a parameter in findrecord?
    By P5C768 in forum Programming
    Replies: 2
    Last Post: 08-20-2009, 04:36 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