Solved

How to do the Selection?

Posted on 2001-06-11
5
143 Views
Last Modified: 2010-05-02
Type     Range     CO     TP     ACT
01     1400     0.8600     0.8800     0.8900
01     1650     1.0000     1.0000     1.0000
01     2200     1.1600     1.1200     1.1000
01     3050     1.2900     1.0900     1.0900
01     4100     1.0900     0.7200     0.7400
01     4250     1.0200     0.7000     0.7800
01     4400     1.1100     0.7900     0.9500
01     99999     1.1200     0.8500     1.0500
02     1400     0.8600     0.8800     0.8900
02     1650     1.0000     1.0000     1.0000
02     2200     1.1600     1.1200     1.1000
02     3050     1.2900     1.0900     1.0900
02     4100     1.0900     0.7200     0.7400
02     4250     1.0200     0.7000     0.7800
02     4400     1.1100     0.7900     0.9500
02     99999     1.1200     0.8500     1.0500


     I would like to ask how to do the selection for the Range and show the
percentage for the Type that I slect before.
     let said user key in the value 1000 in the text box and the type that user choose is
01,and the user choose the Co, that mean that i will get this answer=0.8600.
     pls help me to solve this problem.thanks you
0
Comment
Question by:lbseong
5 Comments
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 100 total points
ID: 6179790
What do you mean by Range, should it check between a range of values or a particular value in the table. If a particular value do this:

rs.open "SELECT " & userchosenfield & " FROM tablename WHERE Range = " & val(txtRange.text) & " AND type = '" & txtType.text & "'",Conn1,adOpenStatic,adOpenReadOnly

Then you can retrieve the values as:

TxtPercentage = rs(0).Value

I assume that you use ADO.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6179860
valli_an is close, however, the value may fall within a range.

Therefore, you must look at the user input (1000 in your example) to see if it falls at or below the range.  Then, you can use a select statement.

Below is an example based only on the information given.  Some assumptions were made for simplicity - if they were poor assumptions, let me know and I will expand them to work entirely programatically (example - that the lowest range is 0 to 1400)

dim iRange as integer    ' user input for range
dim sType as string      ' assuming type is string

iRange = Text1.Text      ' user input
sType = Text2.Text       ' user input

if sRange < 1400 then
    sRange = 1401        ' this covers the 0 to 1400 lowest range
else
    sRange = sRange + 1  'because the range is =<
                         '(equal to or less than)
end if
-----------

now use the select statement as noted above, with a couple of changes... (my table name is Table1)

rs.open "SELECT Table1.Co FROM Table1 WHERE (([Table1]![Range]< " & sRange & ") AND Table1.Type)=" & sType & ")) ORDER BY Table1.Range DESC",Conn1,adOpenStatic,adOpenReadOnly

Notice that sRange is less than the Field 'Range' and that all records are in descending order.  

This will mean that your recordset will include all records of the specified type that are less than the range indicated by the user.  I know - you don't need them all.

** However, the first record of the recordset will always be the one you are looking for.

You simply need to rs.movefirst and then rs(0).value will be the percentage that you are looking for.

Let me know if you have any other questions, or need to make my assumed lowest range of 0 to 1400 calculate within the program.

Hope this helps.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6179868
So actually - every reference to 'sRange' should be 'iRange'.

Sorry for the confusion.

Please - let me know if you have any questions... it's late and I know what I'm trying to tell you, but I'm not sure that others think like I do right now  :)


0
 
LVL 3

Expert Comment

by:sombell
ID: 6180157
lbseong,
You now have 11 ungraded questions under this user name (and I know you have at least one other user name), some of which date back to last year. Either accept and answer to these questions, provide additional information, or delete the questions.

Please deal with your outstanding questions.

Sombell
0
 
LVL 3

Expert Comment

by:modder
ID: 6316267
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question