Results 1 to 6 of 6
  1. #1
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47

    Run time error 2137 but record does exist

    I am receiving the Run time error that I can't find or replace now. But I know the record exists.
    My code is run from a command button and was working fine this morning.


    Could someone please help?
    Code:
    Private Sub Command87_Click()
    Dim str As String
    str = InputBox("What is the Activity Id?", "Siebel Id")
    str = "*" & str & "*"
    DoCmd.FindRecord str, , False, , True
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I can't say that I have experienced this while using code. I have seen a dialog window open and explain that I cannot use Find and Replace, though. IIRC it happens when the intrinsic Find and Replace window is open and the user moves focus somewhere and causes the field being searched to become unavailable. Anyway, I will venture a guess and say you should try and set focus on the control that is bound to the field being searched.

    So, after
    str = InputBox("What is the Activity Id?", "Siebel Id")

    and before
    DoCmd.FindRecord str, , False, , True

    Place a SetFocus
    Me.ControlName.Setfocus

  3. #3
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47
    Thank you for that, but unfortunately I am still getting the run time error.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I tested it out and moving focus is not enough to create the error. Access seems to remember where the focus was last and searches that field. If the last control to have focus is not searchable, Access will look for the next available.

    It seems the code and scenario you have presented is not the whole picture. Perhaps you are using this code behind a form that does not have a control that is searchable. The only way I was able to reproduce the error is with the following ...

    Code:
    'Because the user clicked the Button
    'focus is currently on the Button Control
    Dim str As String
    str = InputBox("What is the Activity Id?", "Siebel Id")
    str = "*" & str & "*"
    Me.MainIndex.Enabled = False
    Me.Text1.Enabled = False
    Me.Text4.Enabled = False
    'Now we will get the error because there
    'is not a field that is available for the search
    DoCmd.FindRecord str, , False, , True

  5. #5
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47
    Hi.
    I have now learnt that because the form is a Data Entry form, the search wouldn't work. I don't understand why but I managed to turn the DataEntry off when doing a search and this seemed to work fine. Thank you so much for you help and advice.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by coach32 View Post
    ... I don't understand why...
    The data entry property will affect which records are part of the Form's RecordSet. When the form is first opened, there will only be the (one) new record. In fact, there will not be any records within the form's Recordset until you start entering and saving data. Any additional records created (without closing the form) will also be part of the form's RecordSet.

    If you are seeing the error when first opening the form, it is because there are not any "fields" available when the form first opens. There will not be any fields until after you start typing info into a field.

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

Similar Threads

  1. Replies: 1
    Last Post: 11-28-2014, 06:56 PM
  2. Replies: 4
    Last Post: 12-14-2012, 06:33 PM
  3. Replies: 1
    Last Post: 06-04-2012, 03:37 PM
  4. Replies: 2
    Last Post: 01-05-2012, 04:23 AM
  5. Replies: 3
    Last Post: 08-31-2011, 09:37 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