?
Solved

Search Function

Posted on 2003-11-07
8
Medium Priority
?
162 Views
Last Modified: 2010-08-05
I need to be able to search a column of numbers or a column of text values, for a specific number or name in an Access database using a VB form (using a text box to receive the input) and a Search button event handler to launch the search.  I do not know how to do this, any help would be appreciated.  Also, In addition to finding a specific number or name value, once the value is found I need to populate the text boxes that will store the rest of the data from the record.
0
Comment
Question by:bfrancisco
[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
8 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9706197
if you use an ADODC control to connect to the database you can use SQL statements to query the databse.
SELECT * FROM YourTable WHERE ColumnName = 'SearchVal'
that is one possible sql statement to grab search specific results
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9706353
To use the query:

Adodc1.RecordSource = "Select ...
Adodc1.Refresh

To Populate the text boxes, set (in the properties window), their DataSource as the data control (Adodc1), and each one's Datafield to the field name desired.
0
 

Author Comment

by:bfrancisco
ID: 9707051
Here's my code from the search event handler.  When I enter a number that I know exists in the database, I launch the event handler and it returns with break:

Private Sub btnCmdSrch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCmdSrch.Click
        Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
End Sub

Thanks for taking a look at this.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9707307
I'm a bit lost here.
Are you using using VB or Access and which versions.
I only know up to VB6 and Access 2000 & have never had to use an OleDB object.
0
 
LVL 1

Expert Comment

by:fsaims
ID: 9707485
Add this command line in your code: -

 Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
'Add this line
Conn.Open()
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
Conn.Close()
0
 

Author Comment

by:bfrancisco
ID: 9708154
GrahamSkan,
I'm using Vb.Net to create an application.  The application connects to an Access 2000 type database.  The search function will be run from the application, i.e., I trying use a Search command button event handler in a Vb which executes code and an SQL statement which searches through a column in an Access database looking for a specific value.  Once the search function finds the specific value, I want a whole row of data retuned to the Vb form to populate text boxes.

Also, fsaims, I tried your solution but it doesn't work; the code breaks for an unhandled exception error at the Conn.Open() statement.

Thanks for attempting to help.  If each of you can be of further assistance that would be great.  I went out and bought a couple of books today, a Microsoft ADO.NET book by David Sceppa and a VB.NET book by Brian Siler and Jeff Spotts.  I'm hoping to find my solution therein.  Cheers!
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 750 total points
ID: 9709358
Thanks for the feedback and good luck
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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