Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53

    Sorting Query through Forum for range

    Hi guys,



    So I want to sort my records with a query search forum like the one in this video:

    http://www.datapigtechnologies.com/f...earchform.html

    I am getting everything to work except for the range fields.

    i want to be able to insert a range and get records, but at the same time, if I dont put anything, the form will know to just ignore it and bring back results for the other parameters I inserted.

    basicly i want to be able to do something like this:

    In the criteria of the query for range field: like between forms!form!min.value and forms!form!max.value and *

    what i have now is: Between [forms]![RunQuery]![MinSuite_Sort]="Value" And [forms]![RunQuery]![MaxSuite_Sort]="value"

    and when i run it, nothign works.

    I hope what I am asking makes sense if not, tell me and i will try and clarify.

    thank you.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What exactly is the data type of the
    [forms]![RunQuery]![MinSuite_Sort]="Value" And [forms]![RunQuery]![MaxSuite_Sort]="value"
    If they are numbers, you do not need quotes.
    Do you get an error message. If so, then please tell us what it is.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Between [forms]![RunQuery]![MinSuite_Sort]="Value" And [forms]![RunQuery]![MaxSuite_Sort]="value"

    If this is what your statement really looks like, what it translates to is "between False and False", because [forms]![RunQuery]![MinSuite_Sort]="Value" is either true or false, and the same for [forms]![RunQuery]![MaxSuite_Sort]="value"



    Better syntax for your between is :
    Between [forms]![RunQuery]![MinSuite_Sort] And [forms]![RunQuery]![MaxSuite_Sort]

    if your form fields are numeric, or:

    "Between '" & [forms]![RunQuery]![MinSuite_Sort] & "' And '" [forms]![RunQuery]![MaxSuite_Sort] & "'"


    if your form fields are text.

    However, I would be careful in using this, because it would be very easy to make a mistake in the form, and not get the results you expect, for example if you leave one of the values out, or reverse the From and To.

    Access will never "Ignore a parameter.."; it will always use it, so you have to be careful with the between, yhou can't use it like the others; if you leave them both blank, you will get between "" and "" or between 0 and 0, which I suspect will almost always be false.

    Maybe you could give a bit more detail about what you need to do.

    HTH

    John

  4. #4
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    When i run the query, nothing shows up. No error

  5. #5
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Use the Nz() Function to provide a default value. That way, if no value is given, it will use the provided defaults.

    Code:
    Between Nz([forms]![RunQuery]![MinSuite_Sort], #10/12/1492#) And Nz([forms]![RunQuery]![MaxSuite_Sort], Date())
    P.S.
    +1 internets if you recognize the beginning date!

  6. #6
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    YES! This worked! Thankyou! Problem Solved

    EDIT**

    Almost works

    I have to put values for both ranges for it to work, the Default Values are Not Working.

    So when I put nothing I get an error: Run-Time Error '3071'. This epcression is Type Incorrectly, or it is too complex to be evaluated.

    Here is what I have: Between Nz([forms]![Advanced Search]![Unit_Min],0) And Nz([forms]![Advanced Search]![Unit_Max],99999)

    Its probably some simple fix that will make me feel stupid, but w/e Im very new to access.

  7. #7
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The error message may be misleading. What is it you are applying the "Between" to? If it is a table field or query field of type numeric integer, try changing the 99999 to 32767, since 32767 is the maximum value for integer type.

    John

  8. #8
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    it is a query field that I am applying the Between criteria to. Note, i also changed the Max to 32767 and I am still getting the same error.

  9. #9
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I'm not seeing anything wrong with your Expression...

    Try replacing it with the following (remove the Nz() Function) and see if you still get an error:
    Code:
    Between 0 And 32767
    If you still get an error, then the problem isn't with that part of the Query.

  10. #10
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    No error when I replace the Criteria with between 0 and 32767

  11. #11
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In what context are you using the query? Is the form open when you run the query?

    John

  12. #12
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    I use the Form to open the query. So in my form I apply the criteria then I run the Query

  13. #13
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Can we see the actual SQL syntax of that portion of the Query (beginning at "WHERE" and ending at the first "AND" or "OR" after the expression)? That might help us figure out what's happening.

    Also, is this a Summation Query or a regular Select Query (if the Sigma icon is selected, it's a Summation Query)?


    Click image for larger version. 

Name:	dbalilti_summation.jpg 
Views:	8 
Size:	10.3 KB 
ID:	8787

  14. #14
    dbalilti is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    53
    WHERE (((Records.Developer) Like [forms]![Advanced Search].[Developer] & "*") AND ((Records.Region) Like [forms]![Advanced Search].[Region] & "*") AND ((Records.Units) Between Nz([forms]![Advanced Search]![Unit_Min],0) And Nz([forms]![Advanced Search]![Unit_Max],32767)));

    and the Totals is not on.

  15. #15
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I'm pretty sure it actually has more to do with the Records.Developer and Records.Region conditions than Records.Units...

    Let's say I enter the following values in your Form:
    - Developer = Rawb
    - Region = US of A
    - Unit_Min = 5
    - Unit_Max = 100

    The Query would end up looking like this:
    WHERE (((Records.Developer) Like Rawb*) AND ((Records.Region) Like US of A*) AND ((Records.Units) Between Nz(5,0) And Nz(100,32767)));

    As you can see, the two "Like" expressions have quotes incorrectly applied (or not applied at all in this case). I think that's what's causing your error. I just don't know why it would work without the Nz() Functions.

    What we're trying to get it to look like is (with single quotes around "Rawb*" and "US of A*"):
    WHERE (((Records.Developer) Like 'Rawb*') AND ((Records.Region) Like 'US of A*') AND ((Records.Units) Between Nz(5,0) And Nz(100,32767)));

    Depending on how you're getting the expressions into your Query though, that could be hard...

    Do you specify [forms]![Advanced Search].[Developer] in the Query itself or are you passing that in through VBA?

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

Similar Threads

  1. Converting dBase forum to Access forum
    By amerifax in forum Forms
    Replies: 5
    Last Post: 07-03-2012, 01:12 AM
  2. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  3. Replies: 2
    Last Post: 11-25-2010, 11:01 AM
  4. Sorting in a Query (Dates)
    By JohnS in forum Queries
    Replies: 2
    Last Post: 10-23-2009, 03:51 AM
  5. Is this a Query or Sorting problem?
    By bwrobel in forum Queries
    Replies: 2
    Last Post: 07-14-2006, 08:15 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