query to get next highest value
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: query to get next highest value

  1. #1
    Join Date
    May 2015
    Posts
    4

    query to get next highest value

    This the access data table
    item value
    GS40 300
    GS63 600
    GS80 1000
    GS90 4000
    GS95 5000
    GS98 8000

    I am using Vb6 and access 2010 database

    In the above data if i select the value 600 then
    I want a query in vb to get next 2 higher values than 600

    Please help me to to get the query

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,945

    Re: query to get next highest value

    Well assuming that the field is a numeric field you could use a simple query

    Something like
    Code:
    select top 2 item,value where value >600 order by value
    In this case it would return 1000 and 4000
    If the field is text then it would return 8000 only since that is the only one where the first digit >6

    Of course you would need to substitute a variable in there for the 600 so it can work with other values.
    Also would be helpful to know if you are actually using VB6 or if you are talking about the VB that is included in Access which is not really VB at all but rather VBA
    Last edited by DataMiser; May 1st, 2015 at 09:57 PM.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    May 2015
    Posts
    4

    Re: query to get next highest value

    Hi,

    Thanks for your help.

    Yes i am using VB6.

    i have tried the code, the code is:-

    gear_box_table.Open ("select top 2 MODEL_NO,OUTPUT_TORQUE from gear_box_table where MAX_FLANGE = " _
    & dblequote & attachment & dblequote _
    & " And OUTPUT_TORQUE <= " & Val(bto_min) & ") order by OUTPUT_TORQUE")

    it is giving some error:

    Run-time error '-2147217900 (80040e14)':

    <<<one more query

    suppose if i get the value 4028

    then i would like to know the query to get nearest or closest value of 4028 in the value field
    Last edited by suraj14; May 2nd, 2015 at 04:24 AM.

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,945

    Re: query to get next highest value

    What is the error message?
    If Max_Flange is a text field then the value needs to be surrounded by single quotes
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    May 2015
    Posts
    4

    Re: query to get next highest value

    Yes now the code is working.

    Thanks for the support.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




HTML5 Development Center