Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538

    Filter in Header retrieves wrong record

    I have a form with a search combo box in the header that when the contact is selected retrieves the record for that contact. This works without issue except for one contact record. The name of the combo box is mySelector. The SQL statement behind the combo box which is unbound is


    Code:
    SELECT tContacts.ID, tContacts.Last, tContacts.First
    FROM tContacts
    WHERE (((tContacts.ID) Like [forms]![fContacts].[myselector] & "*"))
    ORDER BY tContacts.Last;
    Once the combo box is selected there is an AfterUpdate event

    Code:
    me.requery
    The Correct ID for contact I am searching is 34. The record that comes up has an ID of 3476.

    I have used this procedure in several other DB without issue. This one has me dumbfounded.

    Advise if you need more information or a knockdown version of the DB

    Regards
    Alan

    As I indicated earlier, all works well for every search except the one noted.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    It doesn't sound like you want the wildcard. Try:

    WHERE (((tContacts.ID) = [forms]![fContacts].[myselector]))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Alan,

    Maybe I'm not following, but something seems strange. The LIKE operator works with Text fields so it seems that your ID must be a text datatype???

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Like will "work" with numeric and date/time fields, it just doesn't make sense to use it in my view. I'd suspect that the correct record of 34 is returned in this case, it just isn't the only record returned, and 3476 is the one that shows first. Other times the desired record is probably first, but again not the only record returned.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Paul, when I replace & "*" with WHERE (((tContacts.ID) = [forms]![fContacts].[myselector])) I get a syntax error. Maybe I'm misunderstanding how you are you suggesting I write the SQL statement. You are correct in your statement that it is returning all the records beginning with 34. I had not noticed that before. I am guessing that I never experienced this before due to the limited number of records. Could you give me the entire SQL statement that you think will work? I'd like that to work before I think about reassigning new Contact IDs. From a development standpoint, during the building of the DB, I had Contact IDs up to 307. Then I did something that caused the Automatic Contact IDs to jump to 3476 as the next ID. I don't recall what I did, but felt it really did not make a difference as Contact IDs are just unique numbers to reference a record.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What I posted was the whole criteria, not just a replacement for the wildcard. On a iPad, but just replace the WHERE line in yours with mine.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Thanks Paul, but that gives me an error message Undefined function WHERE in expression. I think I need to do a little bit of reassigning Contact IDs and Foreign IDs in the related tables. Ugh!! I am going to try one more thing and instead of using the ID, I will use the last name as the lookup value in the combo box. Appreciate your input and help on this matter.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe try concatenating the comb box???
    Code:
    WHERE tContacts.ID = " & [forms]![fContacts].[myselector]

  9. #9
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    what if you have multiples (smith,john; smith, albert)?
    Maybe post the new problem version? First, I'd check in the immediate window what the combo value is at runtime based on the sql that was working; maybe it's not what you think. If it looks OK, you could dump the sql that the form is based on into a new test query to see the resulting record(s) based on that combo value. Don't forget to factor in the LIKE operator. The form recordsource might be conducive to returning a value(s) other than what you think it should.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Steve, Got an invalid syntax error. Tried adding a second quotation mark after the & and then tried at the end of the expression. Neither worked. Gave invalid syntax error in one case and in the other opened a parameter query box.

    Micon, when I changed the combo box to look up names, it gave the same results as if I was looking up the names using the ID as the bound field. As I indicated earlier to Paul, it does return the expected value, but it also returns 28 other records all having IDs beginning with 34.

    Still sounds like a revamping of Primary ID and Foreign ID

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What is your SQL now? If it worked with like but returned too many records, the revision should pull the one record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Alan,
    Can you post a copy of the database?
    I agree with Paul --normally with an ID you would want
    Code:
    WHERE tContacts.ID = " & [forms]![fContacts].[myselector]
    Your use of Like in this situation is a little different.

  13. #13
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Jack
    I will post a cut down version of the DB later today. There is a lot of confidential data that needs to sanitized first; and the mountains are calling and I need to get my skis on this morning and make some turns.

    Alan

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I understand --nature calls!
    It called me to go golfing this afternoon.
    At least we have our priorities under control...

  15. #15
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Right!

    Here is the knocked down version. I am getting a parameter notice when I open the knocked down file. Am not receiving this in the full file. Just click cancel for now and it should not make a difference in what we are looking at. Look at the properties for the unbound combo box "myselector" and see if you can find an alternative to setting this up so that I only get the one record I want and not all the records that start with 34 as part of the ID. Thanks for looking at this. I hope you had lots of Birdies out there. It was great ski day. We had a dusting of 4 inches of fresh powder on top of 60 inch base. We have had over 200 inches of snow so far this year and they are predicting 18-24 inches over the next couple of days. WooHoo!!!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-17-2017, 08:08 PM
  2. Replies: 4
    Last Post: 11-19-2014, 02:56 PM
  3. Filter Form from header click
    By bikeordie1 in forum Reports
    Replies: 3
    Last Post: 03-01-2013, 03:11 PM
  4. Chart filter based on header value
    By trivanka in forum Reports
    Replies: 3
    Last Post: 02-14-2013, 05:23 PM
  5. What's wrong with this filter?
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 02-21-2011, 12:58 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