Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search

Posted on 2000-05-04
4
Medium Priority
?
162 Views
Last Modified: 2010-05-02
Hi, I want to search a database.  I want to be able to search by either age or eye color.  I have two radio buttons.  One called radEye and one called radAge.  I have a text box where I will input what I am searching for called txtSearch.  And, I have a command button called cmdSearch to press when I am ready to search.  Any help or creative ideas would be much appreciated.
0
Comment
Question by:zippy221
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Expert Comment

by:AZWolf7
ID: 2778766
OK, need more info on this, but here's the gist of it:

Dim sSQL as string

sSQL = "select * from Mytable where "

If radEye then
     sSQL = sSQL & " eyecolor = '" & txtSearch & "'"
Else
     sSQL = sSQL & " age = " & CInt(txtSearch)
End If

This code made the following assumptions:
the table is called Mytable
the fields are called eyecolor and age respectively
eyecolor is a string
age is an integer
they have selected one of the values radEye or radAge
if they selected radAge, they entered a valid number



0
 

Expert Comment

by:AZWolf7
ID: 2778771
Ooops, it also assumes you can run this dynamically built SQL statement. The theory is create the SQL statement, and execute it to get your recordset you want.

0
 

Author Comment

by:zippy221
ID: 2781298
Okay here is more info.  There are 3 text boxes that display the information from the database.  These text boxes are: txtEyeColor, txtAge, txtName.  The database is called dbStudy.  The table is called tblColor.  I will need to create some sort of search where the user can search by either Eye Color or Age.  
0
 

Accepted Solution

by:
AZWolf7 earned 200 total points
ID: 2782132
'I will assume you are using ADO. this pretty much writes your whole routine for you, but you'llhave a few small holes to fill like the connection string, or converting to the data access type you are using.

Dim sSQL as string
Dim objRS as ADODB.Recordset
Dim objConn as ADODB.Connection

Set objConn = New ADODB.Connection
With objConn
    .ConnectionString = 'insert your connection string here
    .Open
End With
Set objRS = New ADODB.Recordset

sSQL = "select * from Mytable where " 

If radEye then
     sSQL = sSQL & " eyecolor = '" & txtSearch & "'"
Else
     sSQL = sSQL & " age = " & CInt(txtSearch)
End If

objRS.ActiveCOnnection = objConn
objRS.Open sSQL

'Check to see if you got any records
If not objRS.EOF and Not objRS.BOF then
    txtEyeColor = Trim(objRS!eyecolor & "")
    If not isnull(objRS!Age) then
        txtAge = objRS!Age
    Else
        txtAge = 0
    End If
    txtName = Trim(objRS!name & "")
Else
    txtEyeColor = ""
    txtAge = ""
    txtName = "Not Found"
end If

Set objRS = Nothing
Set objConn = Nothing

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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