Results 1 to 6 of 6
  1. #1
    Botfly is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    7

    Question Query not working properly using wildcard parameters

    Hello fellow programmers. So, I have been working on a several month long project and a client has discovered this issue with adding up some values. I have figured out the issue but I am unsure why it does not work. Everywhere I look online suggests the exact same solution (to which I already have implemented) but it does not work properly.

    So, here's what is going on: A user can submit a purchase order under a job number. Let's say they submit this under job number '123-12345' for a purchase order of $5. Now, the user submits another purchase order a week later for let's say $1 under the same job number, however, since then the job number has changed to '123-12345x'. This is perfectly fine as the job number sometimes slightly changes. There is a form which they can type a job number and it should not care that there is an 'x' after it. When they type in '123-12345', the total it gives them is $5 when it should be $6.

    So here is the way the code works. TableX has fields called 'Job Number' and 'Price'. A form (let's call it FormX) has a field to enter a job number, and when they do, they press a button so the total price of every object in TableX with the same job number as they entered above gets its price added up for a sum total. Sometimes the job number can slightly change but still be the same job number. Sometimes a letter gets added to the end so there are slight different spellings of the job number in this case. Upon button press, a query looks at TableX and its field called "Job Number" and compares it to the field in FormX using this code:
    Code:
    Like "*" & [Forms]![FormX]![JobNumber] & "*"
    (In this code above, [JobNumber] is the field on FormX that the user enters the job number they want the total purchase order $ amt for that job)



    So, (assuming the user enters '123-12345') with using these wildcards, it should not matter if TableX has an object with the job number 123-12345xyz or 123-12345x or 123-12345. However, if there are multiple entries in TableX that have variations of the job number, then it only queries the objects with (in this case) the simpler spelling.

    Finally, everything about adding up the total Price works just fine. Everything about this works well except with the line of code above. I was under the impression that using "*" would tell the query to not care what comes before/after the "JobNumber" string. However, this is clearly not the case here. I have tried everything I can think of and used different syntax with no luck. Perhaps someone understands what I am doing wrong here?:confused: Any help would be greatly appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    like "*" & [Forms]![formX]![JobNumber] & "*"

    works just fine in a query.
    But since we cannot see your sql, we cannot debug.

  3. #3
    Botfly is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    7
    I have taken out all irrelevant SQL and heres all of it that affects it:

    Code:
    SELECT [Purchase Orders Table].[Job Number]
    FROM [Purchase Orders Table]
    WHERE ((([Purchase Orders Table].[Job Number]) Like "*" & [Forms]![FormX]![JobNumber] & "*"));

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    I tried it, it works.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Me too.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  6. #6
    Botfly is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    7
    Alright since 2 of you said it worked for you, I figured the difference for why mine doesnt work is something I am overlooking that I think wouldnt affect it. I analyzed everything I have in my query that I didnt mention here. I had a one-to-one relationship between 2 different tables that both had a Job Number field. I do not remember my logic behind doing this. Anyways, I deleted the relationship between those 2 and to my surprise that fixed the problem. It seriously is sometimes the stupid little things that break the code. Thank you June7 and ranman256 for responding so quickly!

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

Similar Threads

  1. UDF in an IN statement not working properly in query
    By CodeLiftSleep in forum Access
    Replies: 6
    Last Post: 02-01-2018, 11:09 PM
  2. Selection Query not working properly
    By zipaway in forum Queries
    Replies: 9
    Last Post: 07-31-2014, 06:56 AM
  3. Replies: 1
    Last Post: 01-16-2013, 10:58 AM
  4. Update Query Not Working Properly !
    By hamxa7 in forum Queries
    Replies: 3
    Last Post: 09-20-2012, 04:58 PM
  5. Query on chart not working properly!
    By Sim_ in forum Queries
    Replies: 0
    Last Post: 10-28-2009, 09:38 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