Results 1 to 11 of 11
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Find Record from a Combo Box


    This is very simple, but I'm stubbing my toe. I put this code in my afterupdate event of my Combo Box.

    Code:
    DoCmd.FindRecord Me.cboInvoice, acEntire, False, acSearchAll

    I am getting a Runtime Error # 2162
    A macro set to one of the current fields properties is failed because of an error in Find Record action argument.

    What am I missing?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I usually use DAO and bookmark

    Looking at the code, it seems like you are searching for a record within the combo and not the Form's RecordSet.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Normally, this is the way it;s done.
    Find the record that matches the control.
    Dim rs As Object



    Set rs = Me.Recordset.Clone
    rs.FindFirst "[acEntire] = " & Str(Nz(Me![cboInvoice], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

    HTH

  4. #4
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Hmmm... "Microsoft Access Database Engine does not recognize acEntire as a valid field name or expression."

    Just to be clear I want my form to jump to the record with the Invoice number.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    acEntire is a constant. maybe see what it is in the immediate window.

    Not sure what this is supposed to do
    rs.FindFirst "[acEntire] = " & Str

    If you are iterating the combo, why not go after the original SQL that the RowSource is based on?

  6. #6
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    This is all a little unintuitive for me. Clones and Bookmarks don't penetrate my skull too well. I'll revisit this on Monday and get back to you.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Still not sure what you are trying to do.

    If you want your form to navigate to a specific record, I would not use the FindRecord method. Maybe .GoToRecord would be more appropriate but, error trapping that method can be tricky. I would employ something like this.


    Code:
    Dim rs As DAO.Recordset
    If Not IsNull(Me.ComboboxName) Then
        If Me.Dirty Then
            Me.Dirty = False
        End If
        Set rs = Me.RecordsetClone
        'rs.FindFirst "[FieldName] = '" & Me.ComboboxName.Column(0) & "'"    'for text field
        rs.FindFirst "[FieldName] = " & Me.ComboboxName.Column(0)             'for number field
        If rs.NoMatch Then
            MsgBox ("Not found")
        Else
              If rs.Bookmarkable = False Then
              MsgBox "Can't bookmark this record"
              Else
              Me.Bookmark = rs.Bookmark
              End If
        End If
        Set rs = Nothing
    End If
    If you are trying to use VBA to change the value in a combo, you will want to use a different approach. Let us know.

  8. #8
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Just want to navigate to a record on my form. I'll try this out on Monday.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I got the FindRecord to work only by running the command in the immediate window. As code behind form, could not get to work. GoToRecord doesn't have text search.

    Use bookmarks and RecordsetClone. It is not necessary to open a recordset object. I've never used the Bookmarkable property, didn't know about it.

    Code:
    If Not IsNull(Me.ComboboxName) Then
        If Me.Dirty Then
            Me.Dirty = False
        End If
        With Me.RecordsetClone
        '.FindFirst "[FieldName] = '" & Me.ComboboxName.Column(0) & "'"    'for text field
        .FindFirst "[FieldName] = " & Me.ComboboxName.Column(0)             'for number field
        If .NoMatch Then
            MsgBox ("Not found")
        Else
            If .Bookmarkable = False Then
              MsgBox "Can't bookmark this record"
            Else
              Me.Bookmark = .Bookmark
            End If
        End If
        End With
    End If
    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
    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 June7 View Post
    ... I've never used the Bookmarkable property, didn't know about it...
    I use it to make sure there is a record that matches between the two recordsets. When using recordset clone, nesting bookmarkable in the following example may be redundant.

    Code:
        If .NoMatch Then
            MsgBox ("Not found")
        Else
            If .Bookmarkable = False Then
              MsgBox "Can't bookmark this record"
            Else

  11. #11
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    June,

    Your code worked.

    I'm not crazy about canabalizing it whole. Like I said, I've never used bookmarks. I'll take time to understand it later.

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

Similar Threads

  1. Combo box to find a record
    By Access_Novice in forum Forms
    Replies: 4
    Last Post: 09-04-2014, 08:48 AM
  2. Replies: 4
    Last Post: 04-01-2014, 02:33 PM
  3. Replies: 21
    Last Post: 07-04-2013, 10:46 AM
  4. Combo to find record on report
    By djclntn in forum Reports
    Replies: 2
    Last Post: 04-03-2012, 02:54 PM
  5. Replies: 5
    Last Post: 11-13-2010, 04:56 PM

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