Results 1 to 11 of 11
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Search drop down not pulling correct record

    Hello all! I have a dropdown search field, based on the name of a project. It has 2 columns, projectname and projectnumber. My code is as follows:


    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[ProjectNo] = '" & Me![Combo118].Column(1) & "'"
    Debug.Print Me![Combo118].Column(1)
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

    As you can see I am referencing Column(1) to actually pull the project number (as it cannot be duplicated). However, the user has duplicated project names. No matter which project name she selects, it only pulls the "other" project. I've debugged it, and get the "other" project number, even when specifically choosing the project that she wants. Clear as mud? So, it seems to not be paying attention to the Column(1) reference. What can I do to fix this?

    I thank you in advance for any light you can shed.

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    try a dot instead of the bang

    Is ProjectNo a string? or number?

    Code:
    Dim rs as DAO.Recordset
    set rs = me.RecordsetClone
    
    
    rs.FindFirst "ProjectNo = '" & Me.Combo118.Column(1) & "'"
    
    
    if not rs.NoMatch then
         Me.BookMark = rs.BookMark
    end if
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    It's a string, they look like this: 10-02-20-017. Thanks for looking!

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I would use an autonumber for the PK. You can still have a project number as written but just not as a PKey.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Make sure the rowsource for the combobox agrees with the available records in the recordset clone.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I wonder if part of the issue is that you're not moving first in the recordset (which I would declare as such and not use Object) but that's just a guess because I would be using an autonumber pk field as the bound column - I use one in every table, except perhaps those that I test with to help others out with some issue. Also, by not using a NoMatch test, your bookmark will be arbitrarily set if a match isn't found. I realize you should have a match based on your data, and I can't explain why it doesn't seem to find it. Also, I have read that if you used a wizard to make this combobox, it uses some combination of .FindFirst and .EOF that is invalid, which was a bug that may not have been fixed.

    BTW, you shouldn't need a recordset object anyway. You should be able to do this with the clone:

    Code:
    With Me.RecordsetClone
        .FindFirst "fieldNameHere =  '" & Me.comboTextValueHere & "'" 
         If Not .NoMatch Then
         Me.Bookmark = .Bookmark
    End With
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I've tried setting the value of an unbound text box to the value of column 1 and searching by that, and it's always the wrong value. The right project number is 07-18-18-017, the wrong one is 10-02-20-017 (the one that always comes up). Debug.print shows the wrong value too. The data from the query looks like this:




    ProjectName ProjectNo BidDate
    Verizon Store Hagerstown 10-02-20-017 10/19/2020
    Verizon Store Hagerstown 07-18-18-017 7/27/2018




    Is there something in the RS function the grabs the first record no matter what? I'm going a little bit nuts. Thank you again for your time!

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Is there something in the RS function the grabs the first record no matter what?
    Pretty sure you cannot use combo column reference in a query but does that apply to a recordset as well? I would not think so, but as I mentioned, the use of a numeric pk field should avoid your issue. In fact, you cannot even rely on a table sort since you're using text as numbers. In that case if sorting ascending 100 comes before 10 so what are you going to do when your data raises that issue?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Micron! You are a Rockstar. That worked slick! I'd still like to know why it wouldn't pull the right record, but that's just my brain. I thank you my friend from the bottom of my heart! Be well.

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    moke123 was the first to suggest .NoMatch (and numeric pk, which I didn't see) so please click the star button below his post and boost his cred. The forum might double his salary if you do that.

    Not sure why the code I wrote fixed it though. Perhaps making a recordset out of a clone? rs as Object instead of Recordset? I'd be interested to see what you have now that works.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I really have no idea. Maybe a combination of things. Before update (when choosing from the combo box) I have an event to set the value of an unbound text box (txtpid) and I use that
    Code:
    With Me.RecordsetClone    .FindFirst "projectno =  '" & Me.txtpid & "'"
         If Not .NoMatch Then
         Me.Bookmark = .Bookmark
        End If
        End With
    and it works and I'm not going to complain! :-) Stars for all of you!

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

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2016, 08:43 AM
  2. Report not pulling correct record
    By jlo33jenn in forum Reports
    Replies: 6
    Last Post: 06-25-2015, 09:14 AM
  3. Replies: 5
    Last Post: 06-11-2015, 06:45 PM
  4. Replies: 4
    Last Post: 02-04-2015, 07:21 PM
  5. Replies: 12
    Last Post: 06-08-2012, 02:37 AM

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