Results 1 to 14 of 14
  1. #1
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43

    Mathematical comparison operator in query

    I have a form that takes in combo box values and then runs a query based on those values. One combo box contains the mathematical comparison operators (<,>,=,etc.) and the other is a text box formatted to general number. I am currently unable to string these together in my WHERE condition and get a correct result. The code and variations of it that I have tried in my WHERE condition are : [Score] & [Forms]![MyFormName]![MathematicalOperator] & [Forms]![MyFormName]![TextBoxNumber]. I am using this to query my table to find values >,<,=,>=,<=,<> to the number in the text box. For example I would like to get values where Score > 3 Any ideas on how to string this together properly?

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    debug print this in the intermediate screen to see what it looks like.
    Ctl+G for screen.


    Dale

  3. #3
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    Sorry, I didn't specify. The query is able to execute, but it seems to be disregarding the condition.

  4. #4
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    What shows in the intermediate screen?

    Dale

  5. #5
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    I have my condition stored in a query and then a DoCmd.OpenQuery once I click a button. So it just opens up the query immediately. I apologize for not specifying this as well.

  6. #6
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    I take it you are not going to answer my question.

    Dale

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Dale, I don't think VBA is being used here, so I don't think the question is being avoided so much as not understood.

    kazaccess, I don't think this type of thing will work directly in a query. You'd probably have to build the query in code, which I suspect is what Dale thinks you're doing. There's a chance the Eval() function would work in the query, but I haven't tested it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    Ok thank you. I will try that and see how it goes.

  9. #9
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Thanks Paul. I thought they were making a WHERE in a form.

    My Bad.

    Dale

  10. #10
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    Ok so I've tried eval() and a CurrentDb.OpenRecordset and it is still not producing the correct result. I'm wondering if I'm maybe missing some sort of quotation syntax or something similar in my WHERE clause?

  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,521
    I did a quick test with Eval() and couldn't get it to work either. I suspect you'll have to do this in code, building an SQL string and including the operator from the form. Knowing the end goal would help. If you're using the query for a form or report, you can adapt this:

    BaldyWeb wherecondition

    to get the operator from the form as well as the value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    I've tried to adapt the wherecondition, but I do not plan on using the query in another form or report, so I don't think I'll be able to get it to work that way. Also, this is an Ad Hoc type of query designed for users who presumably do not have Access experience, so knowing the end goal won't be effective unless they know how to go into the SQL and change the operator themselves. I appreciate all the help. You would think that this type of thing would have a simpler solution, but I guess it's just an uncommon technique.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can also change the SQL of a query with a DAO QueryDef. Bottom line is if you want to provide an interface like that, you'll need to build the SQL in code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure if this will help, but I found this mdb that has a form to create an ad hoc query. You will have to import the form into your dB - it requires a reference to DAO. Maybe you could add the operators to the form and code.
    You can look at the code to generate the SQL and update a saved query instead of a list box.

    THE ACCESS WEB
    Adding a Search form to a database
    http://access.mvps.org/access/forms/frm0045.htm

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

Similar Threads

  1. Replies: 1
    Last Post: 08-27-2012, 02:17 PM
  2. Comparison Query
    By mkc80 in forum Queries
    Replies: 3
    Last Post: 08-15-2012, 01:48 PM
  3. Comparison Query
    By mkc80 in forum Access
    Replies: 3
    Last Post: 08-11-2012, 04:50 PM
  4. Help: Comparison query to find non-matches
    By 14erclimber in forum Queries
    Replies: 6
    Last Post: 06-09-2010, 09:29 AM
  5. Adding Mathematical Operators to my QBF
    By Silver Rain 007 in forum Queries
    Replies: 1
    Last Post: 11-05-2009, 08:54 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