Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search between two tables in VB6

Status
Not open for further replies.

cdhill82083

Technical User
Apr 11, 2003
3
US
I am trying to develop an application that searches between a range of numbers in an access database. I am having trouble figuring out how I would write the SQL query for this or what would be the best way to perform this search? I am not very familiar with database programming in vb6 yet, but I am in the process of learning.
Any help is much appreciated.

Thanks :~)

cdh82083
 
Look up the BETWEEN keyword in SQL Books on Line - it should be your constant comapnion for SQL stuff. Free download available from:


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks johnwm! I will check into this and keep you updated.

cdhill82083
 
Okay, the between operator is not what I need. I'm looking for something more in the way of say:

User inputs a number into txtNum, command button executes SQL statement to find record that matches the following criteria then populates labels with the corresponding data.

strSQL = SELECT * FROM TableName WHERE txtNum >= Field1 and txtNum <= Field2

Am I headed in the right direction? Any help is greatly appreciated.

cdh82083
 
That is basically the same as the between function. i.e.
Code:
strSQL = &quot;SELECT Table1.FIELD1 FROM Table1 WHERE Table1.FIELD1 Between &quot; & txtLowNumber & &quot; And &quot; & txtHighNumber
will return the same as
Code:
strSQL = &quot;SELECT Table1.FIELD1 FROM Table1 WHERE Table1.FIELD1 >= &quot; & txtLowNumber & &quot; And <= &quot; & txtHighNumber


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Check out SQL BOL as I said before!

You've just got your WHERE clause the wrong way round and as ca8msm says, you also need to concatenate the string with the variable.

strSQL = SELECT * FROM TableName WHERE txtNum >= Field1 and txtNum <= Field2

should read:

strSQL = SELECT * FROM TableName WHERE Field1 < &quot; & txtNum & &quot; and Field2 > &quot; & txtNum

If the fields are defined as string rather than numeric, then your variables will be delimited with ticks (') thus:

strSQL = SELECT * FROM TableName WHERE Field1 < '&quot; & txtNum & &quot;' and Field2 > '&quot; & txtNum & &quot;'&quot;

ca8msm - he's using 2 fields not 2 variables

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
oops missed that...sorry!

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I missed it first time round as well!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top