Runtime error 2137: You can't use find or replace now.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kickergirl
    New Member
    • May 2007
    • 22

    Runtime error 2137: You can't use find or replace now.

    I have created a form to allow users to add a new record and/or search for an existing record based on SSN. If the SSN the user enters into SrchID_text is found, the form is populated and a message appears telling the user that the record exists and they can edit existing information or add new information. If the SSN is not found, a new record is supposed to be created and a message appears telling the user that no match was found and they can begin entering data.

    My problem occurs when there are no records in the database.

    How do I get around this?

    Please see code below:

    Code:
    Private Sub SrchID_But_Click()
        Dim strStudentRef As String
        Dim strSearch As String
        
    'Check SrchID_text for Null value or Nill Entry first.
    
        If IsNull(Me![SrchID_Text]) Or (Me![SrchID_Text]) = "" Then
            MsgBox "Please enter a SSN to search for!", vbOKOnly, "Invalid Search Criterion!"
             Me!SrchID_Text.SetFocus
        Exit Sub
    End If
    '---------------------------------------------------------------
            
    'Performs the search using value entered into SrchID_text
    'and evaluates this against values in SSN
     
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("SSN")
        DoCmd.FindRecord Me![SrchID_Text]
            
        SSN.SetFocus
        strStudentRef = SSN.Text
        SrchID_Text.SetFocus
        strSearch = SrchID_Text.Text
            
    'If matching record found fills in data and
    'sets focus on participant's first name and
    'clears search control
    
        If strStudentRef = strSearch Then
            MsgBox "Match Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please edit or add data as needed.", , "Existing Record Found"
            F_Name.SetFocus
            SrchID_Text = ""
    
        'If value not found sets SSN equal to searched SSN and
        'informs user to begin entering data and sets focus on
        'F_Name
    
        Else
               MsgBox "Match Not Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please begin entering data for this new participant.", _
                , "New Participant!"
                DoCmd.GoToRecord , , acNewRec
                SSN.SetFocus
                SSN.Text = strSearch
                LWIA_Combo.SetFocus
             
        End If
    
    End Sub
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Me.Recordset.Re cordCount will let you know if you have at least one record.

    Comment

    • kickergirl
      New Member
      • May 2007
      • 22

      #3
      Exactly how would I incorporate this into my code so that when a user enters the very first record, it will add a new record using the SSN entered?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You mean like a If Me.Recordset.Re cordCount = 0 Then ...?
        From your code you seem to know how to use an If/Then statement.

        Comment

        • kickergirl
          New Member
          • May 2007
          • 22

          #5
          Yes I obviously do... However, I have tried various placements of the If me.recordset.re cordcount = 0 then statement and nothing works

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Originally posted by kickergirl
            Yes I obviously do... However, I have tried various placements of the If me.recordset.re cordcount = 0 then statement and nothing works
            Show me one of your placements.

            Comment

            Working...